Class AbstractFileExtractorTask

  • All Implemented Interfaces:
    MonitoredRunnable
    Direct Known Subclasses:
    GFileSystemExtractAllTask

    public abstract class AbstractFileExtractorTask
    extends Task
    Common base class for tasks that need to extract files from a GFileSystem location.

    • Field Detail

      • rootOutputDirectory

        protected java.io.File rootOutputDirectory
    • Method Detail

      • startExtract

        protected void startExtract​(GFileSystem fs,
                                    GFile srcDir,
                                    TaskMonitor monitor)
                             throws CancelledException,
                                    java.io.IOException
        Starts the file extraction process.
        Parameters:
        fs - the GFileSystem that holds the files
        srcDir - the starting directory to extract, if null, start at root of file system
        rootOutputDirectory - the destination directory
        monitor - TaskMonitor that will be updated with progress and checked for cancel
        Throws:
        CancelledException
        java.io.IOException
      • processDirectory

        protected void processDirectory​(GFile srcGFileDirectory,
                                        java.io.File destDirectory,
                                        TaskMonitor monitor)
                                 throws java.io.IOException,
                                        CancelledException
        Extract the contents of a directory in a GFileSystem into a local file system directory.

        The destination directory is created if not present.

        Parameters:
        srcGFileDirectory - if null, directory is filesystem root
        destDirectory - destination / output directory
        monitor - TaskMonitor to watch and update with progress
        Throws:
        java.io.IOException - if IO problem.
        CancelledException
      • mapSourceFilenameToDest

        protected java.lang.String mapSourceFilenameToDest​(GFile srcFile)
                                                    throws java.io.IOException
        Maps the untrusted, potentially hostile, filename of the source file to a name that is suitable to be used to create a file on the user's local file system.

        NOTE: This base implementation converts relative directory names to spelled-out versions of that directory, eg. "." becomes "dot".

        If you wish to modify this behavior, override this method and return different mappings.

        Parameters:
        srcFile - source file
        Returns:
        String name of the source file, possibly modified to be safer
        Throws:
        java.io.IOException - thrown if name is not mappable and the extract process should stop
      • handleUnexpectedException

        protected boolean handleUnexpectedException​(GFile file,
                                                    java.lang.Exception e)
        Allows custom handling of exceptions that occur during file extraction.

        Return true if the exception should be ignored by the file extraction process, otherwise return false if it should be propagated up the call stack.

        Parameters:
        file - file that was being extracted when the exception happened
        e - the exception
        Returns:
        true if the exception should be suppressed, false if the exception should be thrown
      • getTotalFilesExportedCount

        public int getTotalFilesExportedCount()
        Return the number of files that were exported.

        Returns:
        the number of files that were exported
      • getTotalDirsExportedCount

        public int getTotalDirsExportedCount()
        Return the number of directories that were exported.

        Returns:
        the number of directories that were exported
      • getTotalBytesExportedCount

        public long getTotalBytesExportedCount()
        Return the number of bytes that were exported.

        Returns:
        the number of bytes that were exported