Class FileInput

java.lang.Object
com.pnfsoftware.jeb.core.input.FileInput
All Implemented Interfaces:
IInput

@Ser public final class FileInput extends Object implements IInput
An IInput backed by a filesystem entry. Nested entries inside zip archives are also supported and must be addressed with a bang-separated path, for example /some/path/file.zip!a/b/c/data.bin.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    This flag indicates that the serialization of this object should include a full bytes copy of the underlying file.

    Fields inherited from interface com.pnfsoftware.jeb.core.input.IInput

    IDEAL_HEADER_SIZE
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a file input for a filesystem entry or zip entry path.
    FileInput(File file, boolean hardFail)
    Create a file input for a filesystem entry or zip entry path.
    FileInput(File file, boolean hardFail, boolean readHeader)
    Create a file input for a filesystem entry or zip entry path.
    Create a file input for a filesystem entry or zip entry path.
    FileInput(String path, boolean hardFail)
    Create a file input for a filesystem entry or zip entry path.
    FileInput(String path, boolean hardFail, boolean readHeader)
    Create a file input for a filesystem entry or zip entry path.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Determine whether this input is readable.
    void
    Close that input and free all resources used by this object.
    Get a seekable read-only channel representing the input.
    long
    Provide the current input size of the input data.
    Retrieve the input file.
    Get a read-only, big-endian buffer of the first input bytes.
    Retrieve the optional input name.
    Retrieve the resolved input path.
    Retrieve the optional base used to resolve getPersistedPath().
    Return the path element that would be persisted if this element is serialized.
    Get the input stream.
    boolean
    rebase(String base)
    Force a new base and reopen the file.
    boolean
    Set the base for this input, assuming it is referring to a valid file (i.e.
    void
    setFile(File file)
    Attach a file to this input if it is currently unresolved.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface com.pnfsoftware.jeb.core.input.IInput

    toOutputFile
  • Field Details

    • SER_FLAG_FULL_PERSISTENCE

      public static final int SER_FLAG_FULL_PERSISTENCE
      This flag indicates that the serialization of this object should include a full bytes copy of the underlying file.
      See Also:
  • Constructor Details

    • FileInput

      public FileInput(File file) throws IOException
      Create a file input for a filesystem entry or zip entry path.
      Parameters:
      file - target file
      Throws:
      IOException - on I/O error
    • FileInput

      public FileInput(File file, boolean hardFail) throws IOException
      Create a file input for a filesystem entry or zip entry path.
      Parameters:
      file - target file
      hardFail - if true, fail immediately when the input cannot be resolved
      Throws:
      IOException - on I/O error
    • FileInput

      public FileInput(File file, boolean hardFail, boolean readHeader) throws IOException
      Create a file input for a filesystem entry or zip entry path.
      Parameters:
      file - target file
      hardFail - if true, fail immediately when the input cannot be resolved
      readHeader - if true, eagerly read the input header
      Throws:
      IOException - on I/O error
    • FileInput

      public FileInput(String path) throws IOException
      Create a file input for a filesystem entry or zip entry path.
      Parameters:
      path - filesystem path or bang-separated zip entry path
      Throws:
      IOException - on I/O error
    • FileInput

      public FileInput(String path, boolean hardFail) throws IOException
      Create a file input for a filesystem entry or zip entry path.
      Parameters:
      path - filesystem path or bang-separated zip entry path
      hardFail - if true, fail immediately when the input cannot be resolved
      Throws:
      IOException - on I/O error
    • FileInput

      public FileInput(String path, boolean hardFail, boolean readHeader) throws IOException
      Create a file input for a filesystem entry or zip entry path.
      Parameters:
      path - filesystem path or bang-separated zip entry path
      hardFail - if true, fail immediately when the input cannot be resolved
      readHeader - if true, eagerly read the input header
      Throws:
      IOException - on I/O error
  • Method Details

    • getName

      public String getName()
      Description copied from interface: IInput
      Retrieve the optional input name.
      Specified by:
      getName in interface IInput
      Returns:
      the input name, or null if unnamed
    • getFile

      public File getFile()
      Retrieve the input file.
      Returns:
      the input file, null if the input is invalid
    • getPath

      public String getPath()
      Retrieve the resolved input path.
      Returns:
      the absolute or base-resolved filesystem path, or the bang-separated archive entry path, depending on how this input was configured
    • getPersistedPath

      public String getPersistedPath()
      Return the path element that would be persisted if this element is serialized.
      Returns:
      may be null; may differ from getPath()
    • getPathBase

      public String getPathBase()
      Retrieve the optional base used to resolve getPersistedPath().
      Returns:
      the current path base, or null if none is set
    • rebase

      public boolean rebase(String base)
      Force a new base and reopen the file. The input must not have a base and the current path must not be an absolute path for this method to succeed. (If that is the case, setBase(String) should be used instead.)
      Parameters:
      base - the forced new base
      Returns:
      success indicator
    • setBase

      public boolean setBase(String base)
      Set the base for this input, assuming it is referring to a valid file (i.e. getFile() is non-null).
      Parameters:
      base - the new base; null to remove any existing base
      Returns:
      success indicator
    • setFile

      public void setFile(File file) throws IOException
      Attach a file to this input if it is currently unresolved.
      Parameters:
      file - file to associate with this input
      Throws:
      IOException - if a file is already attached or if the new file cannot be processed
    • canRead

      public boolean canRead()
      Description copied from interface: IInput
      Determine whether this input is readable.
      Specified by:
      canRead in interface IInput
      Returns:
      true if the input can currently be read
    • close

      public void close()
      Description copied from interface: IInput
      Close that input and free all resources used by this object.
      Specified by:
      close in interface IInput
    • getCurrentSize

      public long getCurrentSize()
      Description copied from interface: IInput
      Provide the current input size of the input data.
      Specified by:
      getCurrentSize in interface IInput
      Returns:
      the size, -1 if the size cannot be calculated or if an error occurred
    • getHeader

      public ByteBuffer getHeader()
      Description copied from interface: IInput
      Get a read-only, big-endian buffer of the first input bytes. Clients should not attempt to modify or directly access that buffer. The initial position is set to 0. It is recommended that implementations provide at least IInput.IDEAL_HEADER_SIZE bytes.
      Specified by:
      getHeader in interface IInput
      Returns:
      a unique buffer; on error, the returned buffer is null (unlike other methods declared in this interface, this method does not throw IOException)
    • getChannel

      public SeekableByteChannel getChannel() throws IOException
      Description copied from interface: IInput
      Get a seekable read-only channel representing the input. Each call returns a unique channel. Clients should use this method to efficiently read at various locations within the given input.
      Specified by:
      getChannel in interface IInput
      Returns:
      a unique seekable channel
      Throws:
      IOException - on IO error
    • getStream

      public InputStream getStream() throws IOException
      Description copied from interface: IInput
      Get the input stream. Each call returns a unique stream. Implementors should offer this method for convenience. The implementor is responsible for closing non-closed streams when IInput.close() is called.
      Specified by:
      getStream in interface IInput
      Returns:
      a unique input stream
      Throws:
      IOException - on IO error
    • toString

      public String toString()
      Overrides:
      toString in class Object