Class SalmonFileInputStream

java.lang.Object
java.io.InputStream
com.mku.salmon.streams.SalmonFileInputStream
All Implemented Interfaces:
Closeable, AutoCloseable

public class SalmonFileInputStream extends InputStream
Implementation of a Java InputStream for seeking and reading a SalmonFile. This class provides a seekable source with parallel substreams and cached buffers for performance.
  • Constructor Details

    • SalmonFileInputStream

      public SalmonFileInputStream(SalmonFile salmonFile, int buffersCount, int bufferSize, int threads, int backOffset) throws IOException
      Instantiate a seekable stream from an encrypted file source
      Parameters:
      salmonFile - The source file.
      buffersCount - Number of buffers to use.
      bufferSize - The length of each buffer.
      threads - The number of threads/streams to source the file in parallel.
      backOffset - The back offset.
      Throws:
      IOException - Thrown if there is an IO error.
  • Method Details

    • skip

      public long skip(long bytes)
      Skip a number of bytes.
      Overrides:
      skip in class InputStream
      Parameters:
      bytes - the number of bytes to be skipped.
      Returns:
      The byte skipped
    • reset

      public void reset()
      Overrides:
      reset in class InputStream
    • read

      public int read() throws IOException
      Read a byte from the stream.
      Specified by:
      read in class InputStream
      Returns:
      The bytes read
      Throws:
      IOException - Thrown if there is an IO error.
    • read

      public int read(byte[] buffer, int offset, int count) throws IOException
      Reads and decrypts the contents of an encrypted file
      Overrides:
      read in class InputStream
      Parameters:
      buffer - The buffer that will store the decrypted contents
      offset - The position on the buffer that the decrypted data will start
      count - The length of the data requested
      Throws:
      IOException
    • getSize

      public long getSize()
      Get the size of the stream.
      Returns:
      The size
    • getPositionStart

      public long getPositionStart()
    • setPositionStart

      public void setPositionStart(long pos)
    • setPositionEnd

      public void setPositionEnd(long pos)
    • close

      public void close() throws IOException
      Close the stream and associated backed streams and clear buffers.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class InputStream
      Throws:
      IOException - Thrown if there is an IO error.