Class FileUtils

java.lang.Object
org.kendar.sync.lib.utils.FileUtils

public class FileUtils extends Object
Utility class for file operations.
  • Constructor Details

    • FileUtils

      public FileUtils()
  • Method Details

    • readFile

      public static String readFile(String filename) throws IOException
      Throws:
      IOException
    • readFile

      public static String readFile(Path lastCompactLogPath) throws IOException
      Throws:
      IOException
    • listFiles

      public static List<FileInfo> listFiles(File directory, String baseDir) throws IOException
      Lists all files in a directory recursively.
      Parameters:
      directory - The directory to list
      baseDir - The base directory for calculating relative paths
      Returns:
      A list of file information
      Throws:
      IOException - If an I/O error occurs
    • makeUniformPath

      public static String makeUniformPath(String path)
    • calculateFileDifferences

      public static Map<String,List<FileInfo>> calculateFileDifferences(List<FileInfo> sourceFiles, List<FileInfo> targetFiles, BackupType backupType)
      Calculates the files that need to be transferred and deleted.
      Parameters:
      sourceFiles - The source files
      targetFiles - The target files
      backupType - The backup type
      Returns:
      A map with the files to transfer and delete
    • getTargetPath

      public static String getTargetPath(FileInfo file, String targetDir, BackupType backupType)
      Gets the target path for a file based on the backup type.
      Parameters:
      file - The file
      targetDir - The target directory
      backupType - The backup type
      Returns:
      The target path
    • createDirectoryIfNotExists

      public static void createDirectoryIfNotExists(File directory) throws IOException
      Creates a directory if it doesn't exist.
      Parameters:
      directory - The directory to create
      Throws:
      IOException - If an I/O error occurs
    • setFileTimes

      public static void setFileTimes(File file, Instant creationTime, Instant modificationTime) throws IOException
      Sets the file times.
      Parameters:
      file - The file
      creationTime - The creation time
      modificationTime - The modification time
      Throws:
      IOException - If an I/O error occurs
    • setFileTimesToEpoch

      public static void setFileTimesToEpoch(File file) throws IOException
      Sets the file times to epoch (1970-01-01 00:00:00).
      Parameters:
      file - The file
      Throws:
      IOException - If an I/O error occurs
    • delete

      public static void delete(File file) throws IOException
      Deletes a file or directory.
      Parameters:
      file - The file or directory to delete
      Throws:
      IOException - If an I/O error occurs
    • copyFile

      public static void copyFile(File source, File target) throws IOException
      Copies a file.
      Parameters:
      source - The source file
      target - The target file
      Throws:
      IOException - If an I/O error occurs
    • readFile

      public static byte[] readFile(File file) throws IOException
      Reads a file into a byte array.
      Parameters:
      file - The file to read
      Returns:
      The file contents as a byte array
      Throws:
      IOException - If an I/O error occurs
    • writeFile

      public static void writeFile(File file, byte[] data) throws IOException
      Writes a byte array to a file.
      Parameters:
      file - The file to write to
      data - The data to write
      Throws:
      IOException - If an I/O error occurs
    • deleteDirectoryContents

      public static boolean deleteDirectoryContents(Path directory) throws IOException
      Deletes all files and subdirectories in the specified directory. The directory itself is not deleted.
      Parameters:
      directory - The directory to clean
      Returns:
      true if all files were deleted successfully, false otherwise
      Throws:
      IOException - If an I/O error occurs