Package io.github.astrapi69.file.copy
Class CopyFileExtensions
- java.lang.Object
-
- io.github.astrapi69.file.copy.CopyFileExtensions
-
public final class CopyFileExtensions extends java.lang.Object
The classCopyFileExtensions
helps you to copy files or directories.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
copyDirectory(java.io.File source, java.io.File destination)
Copies the given source directory to the given destination directory.static boolean
copyDirectory(java.io.File source, java.io.File destination, boolean lastModified)
Copies the given source directory to the given destination directory with the option to set the lastModified time from the given destination file or directory.static boolean
copyDirectoryWithFileFilter(java.io.File source, java.io.File destination, java.io.FileFilter fileFilter, boolean lastModified)
Copies all files that match to the FileFilter from the given source directory to the given destination directory with the option to set the lastModified time from the given destination file or directory.static boolean
copyDirectoryWithFileFilter(java.io.File source, java.io.File destination, java.io.FileFilter includeFileFilter, java.io.FileFilter excludeFileFilter, boolean lastModified)
Copies all files that match to the given includeFileFilter and does not copy all the files that match the excludeFileFilter from the given source directory to the given destination directory with the option to set the lastModified time from the given destination file or directory.static boolean
copyDirectoryWithFileFilter(java.io.File source, java.io.File destination, java.io.FileFilter includeFileFilter, java.io.FileFilter excludeFileFilter, java.util.Collection<java.io.File> excludeFiles, boolean lastModified)
Copies all files that match to the given includeFileFilter and does not copy all the files that match the excludeFileFilter from the given source directory to the given destination directory with the option to set the lastModified time from the given destination file or directory.static boolean
copyDirectoryWithFilenameFilter(java.io.File source, java.io.File destination, java.io.FilenameFilter filenameFilter, boolean lastModified)
Copies all files that match to the FilenameFilter from the given source directory to the given destination directory with the option to set the lastModified time from the given destination file or directory.static boolean
copyDirectoryWithFilenameFilter(java.io.File source, java.io.File destination, java.io.FilenameFilter includeFilenameFilter, java.io.FilenameFilter excludeFilenameFilter, boolean lastModified)
Copies all files that match to the given includeFilenameFilter and does not copy all the files that match the excludeFilenameFilter from the given source directory to the given destination directory with the option to set the lastModified time from the given destination file or directory.static boolean
copyFile(java.io.File source, java.io.File destination)
Copies the given source file to the given destination file.static boolean
copyFile(java.io.File source, java.io.File destination, boolean lastModified)
Copies the given source file to the given destination file with the option to set the lastModified time from the given destination file.static boolean
copyFile(java.io.File source, java.io.File destination, java.nio.charset.Charset sourceEncoding, java.nio.charset.Charset destinationEncoding, boolean lastModified)
Copies the given source file to the given destination file with the given source encodings and destination encodings.static void
copyFiles(java.util.List<java.io.File> sources, java.io.File destination, java.nio.charset.Charset sourceEncoding, java.nio.charset.Charset destinationEncoding, boolean lastModified)
Copies the given source file to the given destination file with the given source encodings and destination encodings.static boolean
copyFileToDirectory(java.io.File source, java.io.File destinationDir)
Copies the given source file to the given destination directory.static boolean
copyFileToDirectory(java.io.File source, java.io.File destinationDir, boolean lastModified)
Copies the given source file to the given destination directory with the option to set the lastModified time from the given destination directory.static java.io.File
newBackupOf(java.io.File file, java.nio.charset.Charset sourceEncoding, java.nio.charset.Charset destinationEncoding)
Creates a backup file in the same directory with the same name of the given file and with the extension of '*.bak'.
-
-
-
Method Detail
-
copyDirectory
public static boolean copyDirectory(java.io.File source, java.io.File destination) throws FileIsSecurityRestrictedException, java.io.IOException, FileIsADirectoryException, FileIsNotADirectoryException, DirectoryAlreadyExistsException
Copies the given source directory to the given destination directory.- Parameters:
source
- The source directory.destination
- The destination directory.- Returns:
- 's true if the directory is copied, otherwise false.
- Throws:
FileIsSecurityRestrictedException
- Is thrown if the source file is security restricted.java.io.IOException
- Is thrown if an error occurs by reading or writing.FileIsADirectoryException
- Is thrown if the destination file is a directory.FileIsNotADirectoryException
- Is thrown if the source file is not a directory.DirectoryAlreadyExistsException
- Is thrown if the directory all ready exists.
-
copyDirectory
public static boolean copyDirectory(java.io.File source, java.io.File destination, boolean lastModified) throws FileIsSecurityRestrictedException, java.io.IOException, FileIsADirectoryException, FileIsNotADirectoryException, DirectoryAlreadyExistsException
Copies the given source directory to the given destination directory with the option to set the lastModified time from the given destination file or directory.- Parameters:
source
- The source directory.destination
- The destination directory.lastModified
- Flag the tells if the attribute lastModified has to be set with the attribute from the destination file.- Returns:
- 's true if the directory is copied, otherwise false.
- Throws:
FileIsSecurityRestrictedException
- Is thrown if the source file is security restricted.java.io.IOException
- Is thrown if an error occurs by reading or writing.FileIsADirectoryException
- Is thrown if the destination file is a directory.FileIsNotADirectoryException
- Is thrown if the source file is not a directory.DirectoryAlreadyExistsException
- Is thrown if the directory all ready exists.
-
copyDirectoryWithFileFilter
public static boolean copyDirectoryWithFileFilter(java.io.File source, java.io.File destination, java.io.FileFilter fileFilter, boolean lastModified) throws java.io.IOException, FileIsNotADirectoryException, FileIsADirectoryException, FileIsSecurityRestrictedException, DirectoryAlreadyExistsException
Copies all files that match to the FileFilter from the given source directory to the given destination directory with the option to set the lastModified time from the given destination file or directory.- Parameters:
source
- The source directory.destination
- The destination directory.fileFilter
- The FileFilter for the files to be copied. If null all files will be copied.lastModified
- Flag the tells if the attribute lastModified has to be set with the attribute from the destination file.- Returns:
- 's true if the directory is copied, otherwise false.
- Throws:
java.io.IOException
- Is thrown if an error occurs by reading or writing.FileIsNotADirectoryException
- Is thrown if the source file is not a directory.FileIsADirectoryException
- Is thrown if the destination file is a directory.FileIsSecurityRestrictedException
- Is thrown if the source file is security restricted.DirectoryAlreadyExistsException
- Is thrown if the directory all ready exists.
-
copyDirectoryWithFileFilter
public static boolean copyDirectoryWithFileFilter(java.io.File source, java.io.File destination, java.io.FileFilter includeFileFilter, java.io.FileFilter excludeFileFilter, boolean lastModified) throws java.io.IOException, FileIsNotADirectoryException, FileIsADirectoryException, FileIsSecurityRestrictedException, DirectoryAlreadyExistsException
Copies all files that match to the given includeFileFilter and does not copy all the files that match the excludeFileFilter from the given source directory to the given destination directory with the option to set the lastModified time from the given destination file or directory.- Parameters:
source
- The source directory.destination
- The destination directory.includeFileFilter
- The FileFilter for the files to be copied. If null all files will be copied.excludeFileFilter
- The FileFilter for the files to be not copied. If null no files will be excluded by copy process.lastModified
- Flag the tells if the attribute lastModified has to be set with the attribute from the destination file.- Returns:
- 's true if the directory is copied, otherwise false.
- Throws:
java.io.IOException
- Is thrown if an error occurs by reading or writing.FileIsNotADirectoryException
- Is thrown if the source file is not a directory.FileIsADirectoryException
- Is thrown if the source or destination file is a directory.FileIsSecurityRestrictedException
- Is thrown if the source file is security restricted.DirectoryAlreadyExistsException
- Is thrown if the directory all ready exists.
-
copyDirectoryWithFileFilter
public static boolean copyDirectoryWithFileFilter(java.io.File source, java.io.File destination, java.io.FileFilter includeFileFilter, java.io.FileFilter excludeFileFilter, java.util.Collection<java.io.File> excludeFiles, boolean lastModified) throws java.io.IOException, FileIsNotADirectoryException, FileIsADirectoryException, FileIsSecurityRestrictedException, DirectoryAlreadyExistsException
Copies all files that match to the given includeFileFilter and does not copy all the files that match the excludeFileFilter from the given source directory to the given destination directory with the option to set the lastModified time from the given destination file or directory.- Parameters:
source
- The source directory.destination
- The destination directory.includeFileFilter
- The FileFilter for the files to be copied. If null all files will be copied.excludeFileFilter
- The FileFilter for the files to be not copied. If null no files will be excluded by copy process.excludeFiles
- A list of files that should be not copied. If null no files will be excluded by copy process.lastModified
- Flag the tells if the attribute lastModified has to be set with the attribute from the destination file.- Returns:
- 's true if the directory is copied, otherwise false.
- Throws:
java.io.IOException
- Is thrown if an error occurs by reading or writing.FileIsNotADirectoryException
- Is thrown if the source file is not a directory.FileIsADirectoryException
- Is thrown if the source or destination file is a directory.FileIsSecurityRestrictedException
- Is thrown if the source file is security restricted.DirectoryAlreadyExistsException
- Is thrown if the directory all ready exists.
-
copyDirectoryWithFilenameFilter
public static boolean copyDirectoryWithFilenameFilter(java.io.File source, java.io.File destination, java.io.FilenameFilter filenameFilter, boolean lastModified) throws java.io.IOException, FileIsNotADirectoryException, FileIsSecurityRestrictedException
Copies all files that match to the FilenameFilter from the given source directory to the given destination directory with the option to set the lastModified time from the given destination file or directory.- Parameters:
source
- The source directory.destination
- The destination directory.filenameFilter
- The FilenameFilter for the files to be copied. If null all files will be copied.lastModified
- Flag the tells if the attribute lastModified has to be set with the attribute from the destination file.- Returns:
- 's true if the directory is copied, otherwise false.
- Throws:
java.io.IOException
- Is thrown if an error occurs by reading or writing.FileIsNotADirectoryException
- Is thrown if the source file is not a directory.FileIsSecurityRestrictedException
- Is thrown if the source file is security restricted.
-
copyDirectoryWithFilenameFilter
public static boolean copyDirectoryWithFilenameFilter(java.io.File source, java.io.File destination, java.io.FilenameFilter includeFilenameFilter, java.io.FilenameFilter excludeFilenameFilter, boolean lastModified) throws java.io.IOException, FileIsNotADirectoryException, FileIsSecurityRestrictedException
Copies all files that match to the given includeFilenameFilter and does not copy all the files that match the excludeFilenameFilter from the given source directory to the given destination directory with the option to set the lastModified time from the given destination file or directory.- Parameters:
source
- The source directory.destination
- The destination directory.includeFilenameFilter
- The FilenameFilter for the files to be copied. If null all files will be copied.excludeFilenameFilter
- The FilenameFilter for the files to be not copied. If null no files will be excluded by copy process.lastModified
- Flag the tells if the attribute lastModified has to be set with the attribute from the destination file.- Returns:
- 's true if the directory is copied, otherwise false.
- Throws:
java.io.IOException
- Is thrown if an error occurs by reading or writing.FileIsNotADirectoryException
- Is thrown if the source file is not a directory.FileIsSecurityRestrictedException
- Is thrown if the source file is security restricted.
-
copyFile
public static boolean copyFile(java.io.File source, java.io.File destination) throws java.io.IOException
Copies the given source file to the given destination file.- Parameters:
source
- The source file.destination
- The destination file.- Returns:
- 's true if the file is copied, otherwise false.
- Throws:
java.io.IOException
- Is thrown if an error occurs by reading or writing.
-
copyFile
public static boolean copyFile(java.io.File source, java.io.File destination, boolean lastModified) throws java.io.IOException
Copies the given source file to the given destination file with the option to set the lastModified time from the given destination file.- Parameters:
source
- The source file.destination
- The destination file.lastModified
- Flag the tells if the attribute lastModified has to be set with the attribute from the destination file.- Returns:
- 's true if the file is copied, otherwise false.
- Throws:
java.io.IOException
- Is thrown if an error occurs by reading or writing.
-
copyFile
public static boolean copyFile(java.io.File source, java.io.File destination, java.nio.charset.Charset sourceEncoding, java.nio.charset.Charset destinationEncoding, boolean lastModified) throws java.io.IOException
Copies the given source file to the given destination file with the given source encodings and destination encodings.- Parameters:
source
- the sourcedestination
- the destinationsourceEncoding
- the source encodingdestinationEncoding
- the destination encodinglastModified
- if true the last modified flag is set.- Returns:
- true if the given file is copied otherwise false.
- Throws:
java.io.IOException
- Signals that an I/O exception has occurred.
-
copyFiles
public static void copyFiles(java.util.List<java.io.File> sources, java.io.File destination, java.nio.charset.Charset sourceEncoding, java.nio.charset.Charset destinationEncoding, boolean lastModified)
Copies the given source file to the given destination file with the given source encodings and destination encodings.- Parameters:
sources
- the files the have to be copieddestination
- the destinationsourceEncoding
- the source encodingdestinationEncoding
- the destination encodinglastModified
- if true the last modified flag is set
-
copyFileToDirectory
public static boolean copyFileToDirectory(java.io.File source, java.io.File destinationDir) throws FileIsNotADirectoryException, java.io.IOException
Copies the given source file to the given destination directory.- Parameters:
source
- The source file to copy in the destination directory.destinationDir
- The destination directory.- Returns:
- 's true if the file is copied to the destination directory, otherwise false.
- Throws:
FileIsNotADirectoryException
- Is thrown if the source file is not a directory.java.io.IOException
- Is thrown if an error occurs by reading or writing.
-
copyFileToDirectory
public static boolean copyFileToDirectory(java.io.File source, java.io.File destinationDir, boolean lastModified) throws FileIsNotADirectoryException, java.io.IOException
Copies the given source file to the given destination directory with the option to set the lastModified time from the given destination directory.- Parameters:
source
- The source directory.destinationDir
- The destination directory.lastModified
- Flag the tells if the attribute lastModified has to be set with the attribute from the destination directory.- Returns:
- 's true if the file is copied to the given directory, otherwise false.
- Throws:
FileIsNotADirectoryException
- Is thrown if the source file is not a directory.java.io.IOException
- Is thrown if an error occurs by reading or writing.
-
newBackupOf
public static java.io.File newBackupOf(java.io.File file, java.nio.charset.Charset sourceEncoding, java.nio.charset.Charset destinationEncoding) throws java.io.IOException
Creates a backup file in the same directory with the same name of the given file and with the extension of '*.bak'.- Parameters:
file
- the file to backup.sourceEncoding
- the source encoding of the file to backup.destinationEncoding
- the destination encoding of the backup file. This can be null.- Returns:
- the created backup file.
- Throws:
java.io.IOException
- Signals that an I/O exception has occurred.
-
-