Class FileLocator

java.lang.Object
electrostatic4j.snaploader.filesystem.FileLocator
All Implemented Interfaces:
InputStreamProvider, StreamProvider, ZipStreamProvider, AutoCloseable
Direct Known Subclasses:
LibraryLocator

public class FileLocator extends Object implements ZipStreamProvider
An Input Stream Provider that locates a filesystem inside a zip compression and provides an input stream object for the located filesystem entry.
  • Field Details

    • fileInputStream

      protected InputStream fileInputStream
      The input stream associated with the located filesystem.
    • fileLocalizingListener

      protected FileLocalizingListener fileLocalizingListener
      An interface object to provide the file-localizing process with a command-state pattern; binding the user application interface with the file localizing lifecycle.
    • compression

      protected ZipFile compression
      Resembles the compression stream provider object, used in the case of external compression routines.
    • filePath

      protected String filePath
      Resembles the file path inside the compression.
  • Constructor Details

    • FileLocator

      public FileLocator(String filePath)
      Locates the library inside the stock jar filesystem.
      Parameters:
      filePath - the path to the dynamic native library inside that jar filesystem
    • FileLocator

      public FileLocator(ZipFile compression, String filePath) throws IOException
      Locates a filesystem inside an external zip compression, the zip filesystem is defined as a ZipFile object and the locatable filesystem is defined as a ZipEntry object.
      Parameters:
      compression - the compression, either ZipFile or JarFile
      filePath - the path to the filesystem inside the compression to be extracted
      Throws:
      IOException - if the jar to be located is not found or an interrupted I/O exception has occurred
    • FileLocator

      protected FileLocator()
      Instantiates an empty filesystem locator object.
  • Method Details

    • initialize

      public void initialize(int size) throws IOException
      Initializes the input stream provider through a file locator routine, either classpath routine or external archive routine.

      Warning: this stack leaks an input stream provider object for the file to be extracted, and the external archive stream provider in case of using an external archive routine to locate the file.

      Specified by:
      initialize in interface StreamProvider
      Parameters:
      size - the size of the buffered IO in bytes or zero for auto filesystem size
      Throws:
      IOException - if an I/O error has occurred.
    • classPathRoutine

      protected void classPathRoutine() throws FilesystemResourceInitializationException
      Commands for the classpath routines.
      Throws:
      FilesystemResourceInitializationException - if the classpath routine fails to locate the file.
    • externalCompressionRoutine

      protected void externalCompressionRoutine(int size) throws IOException
      Commands for the external compression routines.
      Parameters:
      size - custom buffer size, zero for auto filesystem size (warning: file expansion and truncation rules are applied).
      Throws:
      IOException - if an I/O error has occurred.
    • getFileInputStream

      public InputStream getFileInputStream()
      Description copied from interface: InputStreamProvider
      Retrieves the input stream object associated with this filesystem entry.
      Specified by:
      getFileInputStream in interface InputStreamProvider
      Returns:
      an input stream object for this located filesystem
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Throws:
      IOException
    • setFileLocalizingListener

      public void setFileLocalizingListener(FileLocalizingListener fileLocalizingListener)
      Description copied from interface: InputStreamProvider
      Sets the file localizing listener interface object to bind the user application to the file localizing lifecycle.
      Specified by:
      setFileLocalizingListener in interface InputStreamProvider
      Parameters:
      fileLocalizingListener - an implementation object of the file localizing listener
    • getCompression

      public ZipFile getCompression()
      Description copied from interface: ZipStreamProvider
      Retrieves the compression used to locate the files.
      Specified by:
      getCompression in interface ZipStreamProvider
      Returns:
      a zip filesystem object