[io] rename copyContent to copyRecursive

This commit is contained in:
Johannes Frohnmeyer 2022-09-18 14:35:49 +02:00
parent 2d3c1c6a19
commit 29bda2154c
Signed by: Johannes
GPG Key ID: E76429612C2929F4
1 changed files with 13 additions and 4 deletions

View File

@ -75,14 +75,23 @@ public class JFiles {
else Files.delete(path);
}
@Deprecated
public static void copyContent(Path source, Path destination) throws IOException {
copyRecursive(source, destination);
}
@Deprecated
public static void copyContent(Path source, Path target, CopyOption... copyOptions) throws IOException {
copyRecursive(source, target, copyOptions);
}
/**
* If the source is a file, copy it to the target. If it is a directory, create the target directory if it doesn't exist and copy the source directories content there
* @param source The path to copy from
* @param destination The path to copy to
* @throws IOException Something went wrong
*/
public static void copyContent(Path source, Path destination) throws IOException {
copyContent(source, destination, StandardCopyOption.COPY_ATTRIBUTES);
public static void copyRecursive(Path source, Path destination) throws IOException {
copyRecursive(source, destination, StandardCopyOption.COPY_ATTRIBUTES);
}
/**
@ -92,7 +101,7 @@ public class JFiles {
* @param copyOptions Copy options to use
* @throws IOException Something went wrong
*/
public static void copyContent(Path source, Path target, CopyOption... copyOptions) throws IOException {
public static void copyRecursive(Path source, Path target, CopyOption... copyOptions) throws IOException {
if (!Files.exists(target)) Files.createDirectories(target);
boolean replaceExisting = Arrays.asList(copyOptions).contains(StandardCopyOption.REPLACE_EXISTING);
if (Files.isDirectory(source)) {
@ -102,7 +111,7 @@ public class JFiles {
if (!replaceExisting) return;
if (!Files.isDirectory(sourceResolved)) Files.delete(target);
}
copyContent(sourceResolved, targetResolved, copyOptions);
copyRecursive(sourceResolved, targetResolved, copyOptions);
});
} else if (Files.exists(source)) {
if (!Files.exists(target) || replaceExisting) Files.copy(source, target, copyOptions);