Class FileUtils

java.lang.Object
fr.paris.lutece.maven.FileUtils

public class FileUtils extends Object
Utility class to manipulate files.
Note : these methods were copied from plexus-utils 1.2 because :
  • Maven currently uses plexus-utils version 1.1, which doesn't contain copyDirectoryStructureIfModified;
  • Plexus methods do not provide any exclusion method, and we need to exlude .svn directories.
  • Field Details

  • Constructor Details

    • FileUtils

      public FileUtils()
  • Method Details

    • copyDirectoryStructureIfModified

      public static int copyDirectoryStructureIfModified(File sourceDirectory, File destinationDirectory) throws IOException
      Copies an entire directory structure but only source files with timestamp later than the destinations'. Note:
      • It will include empty directories.
      • The sourceDirectory must exists.
      Parameters:
      sourceDirectory - the source directory.
      destinationDirectory - the destination directory.
      Throws:
      IOException - if an I/O exception occurs.
    • copyDirectoryStructure

      public static int copyDirectoryStructure(File sourceDirectory, File destinationDirectory) throws IOException
      Copies an entire directory structure. Note:
      • It will include empty directories.
      • The sourceDirectory must exists.
      Parameters:
      sourceDirectory - the source directory.
      destinationDirectory - the destination directory.
      Throws:
      IOException - if an I/O exception occurs.
    • copyDirectoryWithFilter

      public static void copyDirectoryWithFilter(File sourceDirectory, File destinationDirectory, Function<File,Boolean> fileFilter, Function<String,String> linefilter) throws IOException
      Copies an entire directory structure, with the possibility to filter files and lines Note:
      • It will NOT include empty directories.
      • The sourceDirectory must exists.
      Parameters:
      sourceDirectory - the source directory.
      destinationDirectory - the destination directory.
      fileFilter - the file filter (true copies the file, false ignores it).
      linefilter - the line filter (takes a source line and outputs a possibly modified line).
      Throws:
      IOException - if an I/O exception occurs.
    • copyFileWithLineFilter

      public static void copyFileWithLineFilter(Path sourceFile, Path destinationFile, Function<String,String> linefilter) throws IOException
      Copies a file from source to destination, applying a filter for each line
      Parameters:
      sourceFile - the source file
      destinationFile - the destination file (always written to)
      Throws:
      IOException - if anything goes wrong
    • copyFileToDirectoryIfModified

      public static boolean copyFileToDirectoryIfModified(File source, File destinationDirectory) throws IOException
      Copy file from source to destination only if source is newer than the target file. If destinationDirectory does not exist, it (and any parent directories) will be created. If a file source in destinationDirectory exists, it will be overwritten.
      Parameters:
      source - An existing File to copy.
      destinationDirectory - A directory to copy source into.
      Throws:
      FileNotFoundException - if source isn't a normal file.
      IllegalArgumentException - if destinationDirectory isn't a directory.
      IOException - if source does not exist, the file in destinationDirectory cannot be written to, or an IO error occurs during copying.
    • copyFileIfModified

      public static boolean copyFileIfModified(File source, File destination) throws IOException
      Copy file from source to destination only if source timestamp is later than the destination timestamp. The directories up to destination will be created if they don't already exist. destination will be overwritten if it already exists.
      Parameters:
      source - An existing non-directory File to copy bytes from.
      destination - A non-directory File to write bytes to (possibly overwriting).
      Throws:
      IOException - if source does not exist, destination cannot be written to, or an IO error occurs during copying.
      FileNotFoundException - if destination is a directory (use #copyFileToDirectory).
    • copyFile

      public static void copyFile(File source, File destination) throws IOException
      Copy file from source to destination. The directories up to destination will be created if they don't already exist. destination will be overwritten if it already exists.
      Parameters:
      source - An existing non-directory File to copy bytes from.
      destination - A non-directory File to write bytes to (possibly overwriting).
      Throws:
      IOException - if source does not exist, destination cannot be written to, or an IO error occurs during copying.
      FileNotFoundException - if destination is a directory (use #copyFileToDirectory).
    • deleteFile

      public static void deleteFile(String strFolderPath, String strFileName) throws IOException
      Delete a file
      Parameters:
      strFolderPath - the folder path
      strFileName - the file name
      Throws:
      IOException - exception if there is an error during the deletion