Package com.mku.utils
Class FileCommander
java.lang.Object
com.mku.utils.FileCommander
- Direct Known Subclasses:
SalmonFileCommander
Facade class for file operations.
-
Nested Class Summary
Modifier and TypeClassDescriptionclass
class
-
Constructor Summary
ConstructorDescriptionFileCommander
(FileImporter fileImporter, FileExporter fileExporter, FileSearcher fileSearcher) Instantiate a new file commander object. -
Method Summary
Modifier and TypeMethodDescriptionboolean
True if all jobs are stopped.void
cancel()
Cancel all jobs.void
close()
void
copyFiles
(IVirtualFile[] filesToCopy, IVirtualFile dir, boolean move, Consumer<FileCommander.VirtualFileTaskProgress> onProgressChanged, Function<IVirtualFile, String> autoRename, boolean autoRenameFolders, BiConsumer<IVirtualFile, Exception> onFailed) Copy files to another directory.void
deleteFiles
(IVirtualFile[] filesToDelete, Consumer<FileCommander.VirtualFileTaskProgress> onProgressChanged, BiConsumer<IVirtualFile, Exception> onFailed) Delete files.exportFiles
(IVirtualFile[] filesToExport, IRealFile exportDir, boolean deleteSource, boolean integrity, Consumer<FileCommander.VirtualFileTaskProgress> onProgressChanged, Function<IRealFile, String> autoRename, BiConsumer<IVirtualFile, Exception> onFailed) Export a file from a drive.importFiles
(IRealFile[] filesToImport, IVirtualFile importDir, boolean deleteSource, boolean integrity, Consumer<FileCommander.RealFileTaskProgress> onProgressChanged, Function<IRealFile, String> autoRename, BiConsumer<IRealFile, Exception> onFailed) Import files to the drive.boolean
True if the file search is currently running.boolean
True if file search stopped.boolean
True if jobs are currently running.void
renameFile
(IVirtualFile ifile, String newFilename) Rename an encrypted filesearch
(IVirtualFile dir, String terms, boolean any, FileSearcher.OnResultFoundListener OnResultFound, Consumer<FileSearcher.SearchEvent> OnSearchEvent) Searchvoid
Stop file search.
-
Constructor Details
-
FileCommander
public FileCommander(FileImporter fileImporter, FileExporter fileExporter, FileSearcher fileSearcher) Instantiate a new file commander object.- Parameters:
fileImporter
- The importer to usefileExporter
- The exporter to usefileSearcher
- The searcher to use
-
-
Method Details
-
importFiles
public IVirtualFile[] importFiles(IRealFile[] filesToImport, IVirtualFile importDir, boolean deleteSource, boolean integrity, Consumer<FileCommander.RealFileTaskProgress> onProgressChanged, Function<IRealFile, String> autoRename, BiConsumer<IRealFile, throws ExceptionException> onFailed) Import files to the drive.- Parameters:
filesToImport
- The files to import.importDir
- The target directory.deleteSource
- True if you want to delete the source files when import complete.integrity
- True to apply integrity to imported files.onProgressChanged
- Observer to notify when progress changes.autoRename
- Function to rename file if another file with the same filename existsonFailed
- Observer to notify when a file fails importing- Returns:
- The imported files if completes successfully.
- Throws:
Exception
- Thrown if error occurs during import
-
exportFiles
public IRealFile[] exportFiles(IVirtualFile[] filesToExport, IRealFile exportDir, boolean deleteSource, boolean integrity, Consumer<FileCommander.VirtualFileTaskProgress> onProgressChanged, Function<IRealFile, String> autoRename, BiConsumer<IVirtualFile, throws ExceptionException> onFailed) Export a file from a drive.- Parameters:
filesToExport
- The files to export.exportDir
- The export target directorydeleteSource
- True if you want to delete the source filesintegrity
- True to use integrity verification before exporting filesonProgressChanged
- Observer to notify when progress changes.autoRename
- Function to rename file if another file with the same filename existsonFailed
- Observer to notify when a file fails exporting- Returns:
- The exported files
- Throws:
Exception
- Thrown if error occurs during export
-
deleteFiles
public void deleteFiles(IVirtualFile[] filesToDelete, Consumer<FileCommander.VirtualFileTaskProgress> onProgressChanged, BiConsumer<IVirtualFile, Exception> onFailed) Delete files.- Parameters:
filesToDelete
- The files to delete.onProgressChanged
- The observer to notify when each file is deleted.onFailed
- The observer to notify when a file has failed.
-
copyFiles
public void copyFiles(IVirtualFile[] filesToCopy, IVirtualFile dir, boolean move, Consumer<FileCommander.VirtualFileTaskProgress> onProgressChanged, Function<IVirtualFile, String> autoRename, boolean autoRenameFolders, BiConsumer<IVirtualFile, throws ExceptionException> onFailed) Copy files to another directory.- Parameters:
filesToCopy
- The array of files to copy.dir
- The target directory.move
- True if moving files instead of copying.onProgressChanged
- The progress change observer to notify.autoRename
- The auto rename function to use when files with same filename are foundautoRenameFolders
- True to autorename foldersonFailed
- The observer to notify when failures occur- Throws:
Exception
- Thrown if error occurs during copying
-
cancel
public void cancel()Cancel all jobs. -
isFileSearcherRunning
public boolean isFileSearcherRunning()True if the file search is currently running.- Returns:
- True if search is running
-
isRunning
public boolean isRunning()True if jobs are currently running.- Returns:
- True if a job is running
-
isFileSearcherStopped
public boolean isFileSearcherStopped()True if file search stopped.- Returns:
- True if file search is stopped
-
stopFileSearch
public void stopFileSearch()Stop file search. -
search
public IVirtualFile[] search(IVirtualFile dir, String terms, boolean any, FileSearcher.OnResultFoundListener OnResultFound, Consumer<FileSearcher.SearchEvent> OnSearchEvent) Search- Parameters:
dir
- The directory to start the search.terms
- The terms to search for.any
- True if you want to match any term otherwise match all terms.OnResultFound
- Callback interface to receive notifications when results found.OnSearchEvent
- Callback interface to receive status events.- Returns:
- An array with all the results found.
-
areJobsStopped
public boolean areJobsStopped()True if all jobs are stopped.- Returns:
- True if jobs are stopped
-
close
public void close() -
renameFile
Rename an encrypted file- Parameters:
ifile
- The file to renamenewFilename
- The new file name- Throws:
IOException
- Thrown if there is an IO error.
-