Package com.helger.commons.io.file
Class FileOperationManager
- java.lang.Object
-
- com.helger.commons.io.file.FileOperationManager
-
- All Implemented Interfaces:
IFileOperationManager
@NotThreadSafe public class FileOperationManager extends Object implements IFileOperationManager
Manage file operations, and persist the last errors for later retrieval, as well as offering a callback mechanism for success/error handling.- Author:
- Philip Helger
-
-
Field Summary
Fields Modifier and Type Field Description static IFileOperationManagerINSTANCE
-
Constructor Summary
Constructors Constructor Description FileOperationManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CallbackList<IFileOperationCallback>callbacks()FileIOErrorcopyDirRecursive(File aSourceDir, File aTargetDir)Copy a directory including all child objects.FileIOErrorcopyFile(File aSourceFile, File aTargetFile)Copies the source file to the target file.FileIOErrorcreateDir(File aDir)Create a new directory.FileIOErrorcreateDirIfNotExisting(File aDir)Create a new directory if it does not exist.FileIOErrorcreateDirRecursive(File aDir)Create a new directory.FileIOErrorcreateDirRecursiveIfNotExisting(File aDir)Create a new directory if it does not exist.FileIOErrordeleteDir(File aDir)Delete an existing directory.FileIOErrordeleteDirIfExisting(File aDir)Delete an existing directory if it is existing.FileIOErrordeleteDirRecursive(File aDir)Delete an existing directory including all child objects.FileIOErrordeleteDirRecursiveIfExisting(File aDir)Delete an existing directory including all child objects if it is existing.FileIOErrordeleteFile(File aFile)Delete an existing file.FileIOErrordeleteFileIfExisting(File aFile)Delete a file if it is existing.FileIOErrorgetLastError()EFileIOOperationgetLastOperation()FileIOErrorrenameDir(File aSourceDir, File aTargetDir)Rename a directory.FileIOErrorrenameFile(File aSourceFile, File aTargetFile)Rename a file.StringtoString()
-
-
-
Field Detail
-
INSTANCE
public static final IFileOperationManager INSTANCE
-
-
Method Detail
-
callbacks
@Nonnull @ReturnsMutableObject public CallbackList<IFileOperationCallback> callbacks()
-
getLastError
@Nullable public FileIOError getLastError()
- Specified by:
getLastErrorin interfaceIFileOperationManager- Returns:
- The last error that occurred. May be
nullif no action was yet performed.
-
getLastOperation
@Nullable public EFileIOOperation getLastOperation()
- Specified by:
getLastOperationin interfaceIFileOperationManager- Returns:
- The last operation that was executed, independent of error or
success. May be
nullif no action was performed yet.
-
createDir
@Nonnull public FileIOError createDir(@Nonnull File aDir)
Description copied from interface:IFileOperationManagerCreate a new directory. The direct parent directory already needs to exist.- Specified by:
createDirin interfaceIFileOperationManager- Parameters:
aDir- The directory to be created. May not benull.- Returns:
- A non-
nullerror code.
-
createDirIfNotExisting
@Nonnull public FileIOError createDirIfNotExisting(@Nonnull File aDir)
Description copied from interface:IFileOperationManagerCreate a new directory if it does not exist. The direct parent directory already needs to exist.- Specified by:
createDirIfNotExistingin interfaceIFileOperationManager- Parameters:
aDir- The directory to be created if it does not exist. May not benull.- Returns:
- A non-
nullerror code.
-
createDirRecursive
@Nonnull public FileIOError createDirRecursive(@Nonnull File aDir)
Description copied from interface:IFileOperationManagerCreate a new directory. The parent directories are created if they are missing.- Specified by:
createDirRecursivein interfaceIFileOperationManager- Parameters:
aDir- The directory to be created. May not benull.- Returns:
- A non-
nullerror code.
-
createDirRecursiveIfNotExisting
@Nonnull public FileIOError createDirRecursiveIfNotExisting(@Nonnull File aDir)
Description copied from interface:IFileOperationManagerCreate a new directory if it does not exist. The direct parent directory already needs to exist.- Specified by:
createDirRecursiveIfNotExistingin interfaceIFileOperationManager- Parameters:
aDir- The directory to be created if it does not exist. May not benull.- Returns:
- A non-
nullerror code.
-
deleteDir
@Nonnull public FileIOError deleteDir(@Nonnull File aDir)
Description copied from interface:IFileOperationManagerDelete an existing directory. The directory needs to be empty before it can be deleted.- Specified by:
deleteDirin interfaceIFileOperationManager- Parameters:
aDir- The directory to be deleted. May not benull.- Returns:
- A non-
nullerror code.
-
deleteDirIfExisting
@Nonnull public FileIOError deleteDirIfExisting(@Nonnull File aDir)
Description copied from interface:IFileOperationManagerDelete an existing directory if it is existing. The directory needs to be empty before it can be deleted.- Specified by:
deleteDirIfExistingin interfaceIFileOperationManager- Parameters:
aDir- The directory to be deleted. May not benull.- Returns:
- A non-
nullerror code.
-
deleteDirRecursive
@Nonnull public FileIOError deleteDirRecursive(@Nonnull File aDir)
Description copied from interface:IFileOperationManagerDelete an existing directory including all child objects.- Specified by:
deleteDirRecursivein interfaceIFileOperationManager- Parameters:
aDir- The directory to be deleted. May not benull.- Returns:
- A non-
nullerror code.
-
deleteDirRecursiveIfExisting
@Nonnull public FileIOError deleteDirRecursiveIfExisting(@Nonnull File aDir)
Description copied from interface:IFileOperationManagerDelete an existing directory including all child objects if it is existing.- Specified by:
deleteDirRecursiveIfExistingin interfaceIFileOperationManager- Parameters:
aDir- The directory to be deleted. May not benull.- Returns:
- A non-
nullerror code.
-
deleteFile
@Nonnull public FileIOError deleteFile(@Nonnull File aFile)
Description copied from interface:IFileOperationManagerDelete an existing file.- Specified by:
deleteFilein interfaceIFileOperationManager- Parameters:
aFile- The file to be deleted. May not benull.- Returns:
- A non-
nullerror code.
-
deleteFileIfExisting
@Nonnull public FileIOError deleteFileIfExisting(@Nonnull File aFile)
Description copied from interface:IFileOperationManagerDelete a file if it is existing.- Specified by:
deleteFileIfExistingin interfaceIFileOperationManager- Parameters:
aFile- The file to be deleted. May not benull.- Returns:
- A non-
nullerror code.
-
renameDir
@Nonnull public FileIOError renameDir(@Nonnull File aSourceDir, @Nonnull File aTargetDir)
Description copied from interface:IFileOperationManagerRename a directory.- Specified by:
renameDirin interfaceIFileOperationManager- Parameters:
aSourceDir- The original directory name. May not benull.aTargetDir- The destination directory name. May not benull.- Returns:
- A non-
nullerror code.
-
renameFile
@Nonnull public FileIOError renameFile(@Nonnull File aSourceFile, @Nonnull File aTargetFile)
Description copied from interface:IFileOperationManagerRename a file.- Specified by:
renameFilein interfaceIFileOperationManager- Parameters:
aSourceFile- The original file name. May not benull.aTargetFile- The destination file name. May not benull.- Returns:
- A non-
nullerror code.
-
copyDirRecursive
@Nonnull public FileIOError copyDirRecursive(@Nonnull File aSourceDir, @Nonnull File aTargetDir)
Description copied from interface:IFileOperationManagerCopy a directory including all child objects.- Specified by:
copyDirRecursivein interfaceIFileOperationManager- Parameters:
aSourceDir- The source directory to be copied. May not benull.aTargetDir- The destination directory where to be copied. This directory may not be existing. May not benull.- Returns:
- A non-
nullerror code.
-
copyFile
@Nonnull public FileIOError copyFile(@Nonnull File aSourceFile, @Nonnull File aTargetFile)
Description copied from interface:IFileOperationManagerCopies the source file to the target file.- Specified by:
copyFilein interfaceIFileOperationManager- Parameters:
aSourceFile- The source file to use. May not benull. Needs to be an existing file.aTargetFile- The destination files. May not benulland may not be an existing file.- Returns:
- A non-
nullerror code.
-
-