Package com.helger.io.file
Class FileOperationManager
java.lang.Object
com.helger.io.file.FileOperationManager
- All Implemented Interfaces:
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 -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor without any registered callbacks. -
Method Summary
Modifier and TypeMethodDescription@NonNull com.helger.base.callback.CallbackList<IFileOperationCallback> Get the mutable callback list for file operation events.@NonNull FileIOErrorcopyDirRecursive(@NonNull File aSourceDir, @NonNull File aTargetDir) Copy a directory including all child objects.@NonNull FileIOErrorCopies the source file to the target file.@NonNull FileIOErrorCreate a new directory.@NonNull FileIOErrorcreateDirIfNotExisting(@NonNull File aDir) Create a new directory if it does not exist.@NonNull FileIOErrorcreateDirRecursive(@NonNull File aDir) Create a new directory.@NonNull FileIOErrorcreateDirRecursiveIfNotExisting(@NonNull File aDir) Create a new directory if it does not exist.@NonNull FileIOErrorDelete an existing directory.@NonNull FileIOErrordeleteDirIfExisting(@NonNull File aDir) Delete an existing directory if it is existing.@NonNull FileIOErrordeleteDirRecursive(@NonNull File aDir) Delete an existing directory including all child objects.@NonNull FileIOErrordeleteDirRecursiveIfExisting(@NonNull File aDir) Delete an existing directory including all child objects if it is existing.@NonNull FileIOErrordeleteFile(@NonNull File aFile) Delete an existing file.@NonNull FileIOErrordeleteFileIfExisting(@NonNull File aFile) Delete a file if it is existing.@Nullable FileIOError@Nullable EFileIOOperation@NonNull FileIOErrorRename a directory.@NonNull FileIOErrorrenameFile(@NonNull File aSourceFile, @NonNull File aTargetFile) Rename a file.toString()
-
Field Details
-
INSTANCE
-
-
Constructor Details
-
FileOperationManager
public FileOperationManager()Default constructor without any registered callbacks.
-
-
Method Details
-
callbacks
@ReturnsMutableObject public @NonNull com.helger.base.callback.CallbackList<IFileOperationCallback> callbacks()Get the mutable callback list for file operation events.- Returns:
- The callback list. Never
null.
-
getLastError
- Specified by:
getLastErrorin interfaceIFileOperationManager- Returns:
- The last error that occurred. May be
nullif no action was yet performed.
-
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
Create 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
Create 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
Create 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
Create 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
Delete 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
Delete 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
Delete 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
Delete 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
Delete an existing file.- Specified by:
deleteFilein interfaceIFileOperationManager- Parameters:
aFile- The file to be deleted. May not benull.- Returns:
- A non-
nullerror code.
-
deleteFileIfExisting
Delete 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
Rename 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
Rename 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
Copy 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
Copies 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.
-
toString
-