Package fr.paris.lutece.maven
Class FileUtils
java.lang.Object
fr.paris.lutece.maven.FileUtils
Utility class to manipulate files.
Note : these methods were copied from plexus-utils 1.2 because :
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intcopyDirectoryStructure(File sourceDirectory, File destinationDirectory) Copies an entire directory structure.static intcopyDirectoryStructureIfModified(File sourceDirectory, File destinationDirectory) Copies an entire directory structure but only source files with timestamp later than the destinations'.static voidcopyDirectoryWithFilter(File sourceDirectory, File destinationDirectory, Function<File, Boolean> fileFilter, Function<String, String> linefilter) Copies an entire directory structure, with the possibility to filter files and lines Note: It will NOT include empty directories.static voidCopy file from source to destination.static booleancopyFileIfModified(File source, File destination) Copy file from source to destination only if source timestamp is later than the destination timestamp.static booleancopyFileToDirectoryIfModified(File source, File destinationDirectory) Copy file from source to destination only if source is newer than the target file.static voidCopies a file from source to destination, applying a filter for each linestatic voiddeleteFile(String strFolderPath, String strFileName) Delete a file
-
Field Details
-
REGEXP_SITE_XDOC_XML
- See Also:
-
REGEXP_SITE_RESOURCES_XML
- See Also:
-
REGEXP_SITE_TECH
- See Also:
-
REGEXP_SITE_TECH_DIRECTORY
- See Also:
-
REGEXP_SITE_XML
- See Also:
-
-
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
sourceDirectorymust 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
sourceDirectorymust 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, throws IOExceptionString> linefilter) Copies an entire directory structure, with the possibility to filter files and lines Note:- It will NOT include empty directories.
- The
sourceDirectorymust 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 IOExceptionCopies a file from source to destination, applying a filter for each line- Parameters:
sourceFile- the source filedestinationFile- 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. IfdestinationDirectorydoes not exist, it (and any parent directories) will be created. If a filesourceindestinationDirectoryexists, it will be overwritten.- Parameters:
source- An existingFileto copy.destinationDirectory- A directory to copysourceinto.- Throws:
FileNotFoundException- ifsourceisn't a normal file.IllegalArgumentException- ifdestinationDirectoryisn't a directory.IOException- ifsourcedoes not exist, the file indestinationDirectorycannot be written to, or an IO error occurs during copying.
-
copyFileIfModified
Copy file from source to destination only if source timestamp is later than the destination timestamp. The directories up todestinationwill be created if they don't already exist.destinationwill be overwritten if it already exists.- Parameters:
source- An existing non-directoryFileto copy bytes from.destination- A non-directoryFileto write bytes to (possibly overwriting).- Throws:
IOException- ifsourcedoes not exist,destinationcannot be written to, or an IO error occurs during copying.FileNotFoundException- ifdestinationis a directory (use#copyFileToDirectory).
-
copyFile
Copy file from source to destination. The directories up todestinationwill be created if they don't already exist.destinationwill be overwritten if it already exists.- Parameters:
source- An existing non-directoryFileto copy bytes from.destination- A non-directoryFileto write bytes to (possibly overwriting).- Throws:
IOException- ifsourcedoes not exist,destinationcannot be written to, or an IO error occurs during copying.FileNotFoundException- ifdestinationis a directory (use#copyFileToDirectory).
-
deleteFile
Delete a file- Parameters:
strFolderPath- the folder pathstrFileName- the file name- Throws:
IOException- exception if there is an error during the deletion
-