Class FileExtractor

java.lang.Object
electrostatic4j.snaploader.filesystem.FileExtractor
All Implemented Interfaces:
OutputStreamProvider, StreamProvider, AutoCloseable
Direct Known Subclasses:
ConcurrentFileExtractor

public class FileExtractor extends Object implements OutputStreamProvider
Extracts a filesystem from a zip compression to a destination filesystem.
  • Field Details

    • fileLocator

      protected FileLocator fileLocator
      Locates a filesystem inside a zip compression.
    • fileOutputStream

      protected OutputStream fileOutputStream
      Provides an output byte stream for this FileExtractor object.
    • fileExtractionListener

      protected FileExtractionListener fileExtractionListener
      An interface object to provide the extraction process with a command-state pattern.
    • destination

      protected String destination
      An absolute path for the destination filesystem of the extraction process.
  • Constructor Details

    • FileExtractor

      public FileExtractor(FileLocator fileLocator, String destination)
      Instantiates a filesystem extractor object with a filesystem locator and a destination filesystem.
      Parameters:
      fileLocator - locates a filesystem inside a zip compression
      destination - an absolute filesystem path representing the extraction destination filesystem
    • FileExtractor

      protected FileExtractor()
      Instantiates an empty filesystem extractor.
  • Method Details

    • initialize

      public void initialize(int size) throws Exception
      Description copied from interface: StreamProvider
      Initializes the buffered stream handler object.
      Specified by:
      initialize in interface StreamProvider
      Parameters:
      size - the size of the buffered IO in bytes or zero for auto filesystem size
      Throws:
      Exception
    • extract

      public void extract() throws IOException, FileNotFoundException
      Commands and Extract the specified filesystem to the specified destination filesystem.

      Warning: this function leaks buffered streams; this vision was attained for freedom of use, but the user application must keep in mind that stream closure and resources release must be attained either through the extraction completed and failure listeners, or through a try-with resources.

      Throws:
      IOException - if the input/output streams has failed or an interrupted I/O operation has occurred.
      FileNotFoundException - if the file locator has failed to locate the file inside the compression for the extraction process.
    • close

      public void close() throws Exception
      Specified by:
      close in interface AutoCloseable
      Throws:
      Exception
    • getFileOutputStream

      public OutputStream getFileOutputStream()
      Description copied from interface: OutputStreamProvider
      Retrieves the output stream object associated with this provider.
      Specified by:
      getFileOutputStream in interface OutputStreamProvider
      Returns:
      an output stream provider object to extract the filesystem
    • getFileLocator

      public InputStreamProvider getFileLocator()
      Description copied from interface: OutputStreamProvider
      Retrieves the input stream provider object (the filesystem locator object).
      Specified by:
      getFileLocator in interface OutputStreamProvider
      Returns:
      an input stream provider object that is the filesystem locator object
    • setExtractionListener

      public void setExtractionListener(FileExtractionListener fileExtractionListener)
      Sets the extraction listener action to dispatch the FileExtractionListener.onExtractionCompleted(FileExtractor) when the extraction task is completed.
      Parameters:
      fileExtractionListener - an implementation object of the extraction listener dispatched when the extraction is completed