Package com.mku.utils

Class FileCommander

java.lang.Object
com.mku.utils.FileCommander
Direct Known Subclasses:
SalmonFileCommander

public class FileCommander extends Object
Facade class for file operations.
  • Constructor Details

    • FileCommander

      public FileCommander(FileImporter fileImporter, FileExporter fileExporter, FileSearcher fileSearcher)
      Instantiate a new file commander object.
      Parameters:
      fileImporter - The importer to use
      fileExporter - The exporter to use
      fileSearcher - 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,Exception> onFailed) throws Exception
      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 exists
      onFailed - 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,Exception> onFailed) throws Exception
      Export a file from a drive.
      Parameters:
      filesToExport - The files to export.
      exportDir - The export target directory
      deleteSource - True if you want to delete the source files
      integrity - True to use integrity verification before exporting files
      onProgressChanged - Observer to notify when progress changes.
      autoRename - Function to rename file if another file with the same filename exists
      onFailed - 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,Exception> onFailed) throws Exception
      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 found
      autoRenameFolders - True to autorename folders
      onFailed - 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

      public void renameFile(IVirtualFile ifile, String newFilename) throws IOException
      Rename an encrypted file
      Parameters:
      ifile - The file to rename
      newFilename - The new file name
      Throws:
      IOException - Thrown if there is an IO error.