Class FileUtils

java.lang.Object
FileUtils

public class FileUtils extends Object
Utility class for common file operations used by the UI and import helpers.

Methods in this class are convenience wrappers around Files which add simple error handling and small UI prompts when user interaction is required.

Since:
1.0.0
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Private constructor to prevent instantiation of this utility class.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    copyDirectory(Path sourceDir, Path destDir)
    Recursively copy a directory tree from sourceDir to destDir.
    static void
    copyDirectoryAtomically(Path sourceDir, Path destDir)
    Attempt to copy an entire directory atomically; if any copy fails the destination tree will be deleted to avoid partial state.
    static void
    Copy directory tree but prompt for conflicts.
    static void
    Recursively delete a directory.
    static boolean
    Prompt the user for conflict resolution when a destination path already exists.
    static boolean
    hasEnoughDiskSpace(Path sourceDir, Path destDir)
    Estimate whether the destination has enough usable space to copy the full contents of the source directory.
    static void
    Open the operating system's file browser at the given path.
    static boolean
    verifyIntegrity(Path sourceDir, Path destDir)
    Verify copied files match the source by checking file presence and size.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • FileUtils

      private FileUtils()
      Private constructor to prevent instantiation of this utility class.
  • Method Details

    • copyDirectory

      public static void copyDirectory(Path sourceDir, Path destDir) throws IOException
      Recursively copy a directory tree from sourceDir to destDir. Existing files at the destination will be replaced.
      Parameters:
      sourceDir - root path to copy from
      destDir - root path to copy to
      Throws:
      IOException - when IO fails during traversal or copy
    • openFolder

      public static void openFolder(String path) throws IOException
      Open the operating system's file browser at the given path.
      Parameters:
      path - filesystem path to open
      Throws:
      IOException - if the platform does not support Desktop operations or the path cannot be opened
    • hasEnoughDiskSpace

      public static boolean hasEnoughDiskSpace(Path sourceDir, Path destDir) throws IOException
      Estimate whether the destination has enough usable space to copy the full contents of the source directory. This is a best-effort check.
      Parameters:
      sourceDir - path to source directory
      destDir - path to destination directory (used to query filesystem stats)
      Returns:
      true when available space >= required size
      Throws:
      IOException - on IO errors while computing sizes
    • copyDirectoryAtomically

      public static void copyDirectoryAtomically(Path sourceDir, Path destDir) throws IOException
      Attempt to copy an entire directory atomically; if any copy fails the destination tree will be deleted to avoid partial state.
      Parameters:
      sourceDir - source directory
      destDir - destination directory
      Throws:
      IOException - when copy or rollback fails
    • deleteDirectory

      public static void deleteDirectory(Path dir) throws IOException
      Recursively delete a directory. Errors during deletion are logged but do not stop the traversal.
      Parameters:
      dir - path to remove
      Throws:
      IOException - if an IO error prevents traversal
    • verifyIntegrity

      public static boolean verifyIntegrity(Path sourceDir, Path destDir) throws IOException
      Verify copied files match the source by checking file presence and size.
      Parameters:
      sourceDir - source
      destDir - destination
      Returns:
      true when every file exists in the destination and sizes match
      Throws:
      IOException - on IO error
    • handleFileConflict

      public static boolean handleFileConflict(Path destPath)
      Prompt the user for conflict resolution when a destination path already exists.
      Parameters:
      destPath - conflicted destination path
      Returns:
      true when user chooses to overwrite
    • copyDirectoryWithConflictHandling

      public static void copyDirectoryWithConflictHandling(Path sourceDir, Path destDir) throws IOException
      Copy directory tree but prompt for conflicts. If the user declines for a specific file, that file is skipped while others continue.
      Parameters:
      sourceDir - source path
      destDir - destination path
      Throws:
      IOException - on IO failure