Class StreamInput

java.lang.Object
org.apache.commons.crypto.stream.input.StreamInput
All Implemented Interfaces:
Closeable, AutoCloseable, Input

public class StreamInput extends Object implements Input
The StreamInput class takes a InputStream object and wraps it as Input object acceptable by CryptoInputStream.
  • Field Details

    • buf

      private final byte[] buf
    • bufferSize

      private final int bufferSize
    • in

      final InputStream in
  • Constructor Details

    • StreamInput

      public StreamInput(InputStream inputStream, int bufferSize)
      Constructs a StreamInput.
      Parameters:
      inputStream - the InputStream object.
      bufferSize - the buffer size.
  • Method Details

    • available

      public int available() throws IOException
      Overrides the Input.available(). Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next invocation of a method for this input stream. The next invocation might be the same thread or another thread. A single read or skip of this many bytes will not block, but may read or skip fewer bytes.
      Specified by:
      available in interface Input
      Returns:
      an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking or 0 when it reaches the end of the input stream.
      Throws:
      IOException - if an I/O error occurs.
    • close

      public void close() throws IOException
      Overrides the Input.seek(long). Closes this input and releases any system resources associated with the under layer input.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface Input
      Throws:
      IOException - if an I/O error occurs.
    • read

      public int read(ByteBuffer dst) throws IOException
      Overrides the Input.read(ByteBuffer). Reads a sequence of bytes from input into the given buffer.
      Specified by:
      read in interface Input
      Parameters:
      dst - The buffer into which bytes are to be transferred.
      Returns:
      the total number of bytes read into the buffer, or EOS (-1) if there is no more data because the end of the stream has been reached.
      Throws:
      IOException - if an I/O error occurs.
    • read

      public int read(long position, byte[] buffer, int offset, int length) throws IOException
      Overrides the Input.read(long, byte[], int, int) . Reads up to len bytes of data from the input stream into an array of bytes. An attempt is made to read as many as len bytes, but a smaller number may be read. The number of bytes actually read is returned as an integer.
      Specified by:
      read in interface Input
      Parameters:
      position - the given position within a stream.
      buffer - the buffer into which the data is read.
      offset - the start offset in array buffer.
      length - the maximum number of bytes to read.
      Returns:
      the total number of bytes read into the buffer, or EOS (-1) if there is no more data because the end of the stream has been reached.
      Throws:
      IOException - if an I/O error occurs.
    • seek

      public void seek(long position) throws IOException
      Overrides the Input.seek(long). Seeks to the given offset from the start of the stream. The next read() will be from that location.
      Specified by:
      seek in interface Input
      Parameters:
      position - the offset from the start of the stream.
      Throws:
      IOException - if an I/O error occurs.
    • skip

      public long skip(long n) throws IOException
      Overrides the Input.skip(long). Skips over and discards n bytes of data from this input stream.
      Specified by:
      skip in interface Input
      Parameters:
      n - the number of bytes to be skipped.
      Returns:
      the actual number of bytes skipped.
      Throws:
      IOException - if an I/O error occurs.