diff --git a/base/src/main/java/de/staropensource/engine/base/utility/FileAccess.java b/base/src/main/java/de/staropensource/engine/base/utility/FileAccess.java index 99e2872..841a35e 100644 --- a/base/src/main/java/de/staropensource/engine/base/utility/FileAccess.java +++ b/base/src/main/java/de/staropensource/engine/base/utility/FileAccess.java @@ -628,42 +628,7 @@ public final class FileAccess { } - // -----> File/Directory creation and deletion - /** - * Deletes the file. - * If it doesn't exist, nothing will be done. - * - * @return this instance - * @since v1-alpha8 - */ - public @NotNull FileAccess delete() { - if (exists()) { - Logger.diag("Deleting \"" + path + "\""); - //noinspection ResultOfMethodCallIgnored - file.delete(); - } - return this; - } - - /** - * Marks this file for deletion at engine shutdown. - * - * @return this instance - * @see Engine#shutdown() - * @see Engine#shutdown(int) - * @since v1-alpha8 - */ - public @NotNull FileAccess deleteOnShutdown() { - Logger.diag("Marking \"" + path + "\" for deletion at engine shutdown"); - - // Append path to scheduledDeletion array - List<@NotNull Path> scheduledDeletionList = new ArrayList<>(Arrays.stream(scheduledDeletion).toList()); - scheduledDeletionList.add(path); - scheduledDeletion = scheduledDeletionList.toArray(new Path[0]); - - return this; - } - + // -----> File/Directory creation, moving, copying and deletion /** * Creates the file. * If it already exists, nothing will be done. @@ -725,6 +690,67 @@ public final class FileAccess { return this; } + /** + * Moves this file. + * + * @param destination destination to move this file to + * @return supplied destination + * @throws IOException on an IO error + * @since v1-alpha9 + */ + public @NotNull FileAccess move(@NotNull FileAccess destination) throws IOException { + Files.move(path, destination.path); + return destination; + } + + /** + * Copies this file. + * + * @param destination destination to copy this file to + * @return this instance + * @throws IOException on an IO error + * @since v1-alpha9 + */ + public @NotNull FileAccess copy(@NotNull FileAccess destination) throws IOException { + Files.move(path, destination.path); + return this; + } + + /** + * Deletes this file. + * If it doesn't exist, nothing will be done. + * + * @return this instance + * @since v1-alpha8 + */ + public @NotNull FileAccess delete() { + if (exists()) { + Logger.diag("Deleting \"" + path + "\""); + //noinspection ResultOfMethodCallIgnored + file.delete(); + } + return this; + } + + /** + * Marks this file for deletion at engine shutdown. + * + * @return this instance + * @see Engine#shutdown() + * @see Engine#shutdown(int) + * @since v1-alpha8 + */ + public @NotNull FileAccess deleteOnShutdown() { + Logger.diag("Marking \"" + path + "\" for deletion at engine shutdown"); + + // Append path to scheduledDeletion array + List<@NotNull Path> scheduledDeletionList = new ArrayList<>(Arrays.stream(scheduledDeletion).toList()); + scheduledDeletionList.add(path); + scheduledDeletion = scheduledDeletionList.toArray(new Path[0]); + + return this; + } + // -----> File locking /**