Class ASBufferedInFilter

All Implemented Interfaces:
Closeable, AutoCloseable
Direct Known Subclasses:
COSFilterAESDecryptionDefault, COSFilterASCII85Decode, COSFilterASCIIHexDecode, COSFilterFlateDecode, COSFilterLZWDecode, COSFilterRC4DecryptionDefault, COSPredictorDecode, EexecFilterDecode

public class ASBufferedInFilter extends ASInFilter
Class provides buffered input from input stream. It has two uses. If the ASBufferedInFilter object is used as a buffered stream (e. g. in unseekable parsers) then the buffer holds DECODED bytes read from inlaying stream. Before using the ASBufferedInFilter in this make sure to call initialize() method. In filter classes that are inherited from ASBufferedInFilter the buffer holds ENCODED bytes that are processed into decoded bytes on read() method calls.
Author:
Sergey Shemyakov
  • Field Details

    • START_BUFFER_SIZE

      public static final int START_BUFFER_SIZE
      See Also:
    • BF_BUFFER_SIZE

      public static final int BF_BUFFER_SIZE
      See Also:
    • buffer

      protected byte[] buffer
  • Constructor Details

  • Method Details

    • initialize

      public void initialize() throws IOException
      This method should be called before using ASBufferedInFilter as buffered stream.
      Throws:
      IOException
    • read

      public int read(byte[] buffer, int size) throws IOException
      Description copied from class: ASInFilter
      Overrides:
      read in class ASInFilter
      Throws:
      IOException
    • read

      public int read(byte[] buffer) throws IOException
      Description copied from class: ASInFilter
      Overrides:
      read in class ASInFilter
      Throws:
      IOException
    • readByte

      public byte readByte() throws IOException
      Throws:
      IOException
    • processBuffer

      public int processBuffer(int bytesToProcess)
      Shifts begin marker by up to bytesToProceed bytes to the right of to the end of the buffer if bytesToProceed is too big.
      Parameters:
      bytesToProcess - amount of bytes to shift.
      Returns:
      amount of bytes actually processed.
    • feedBuffer

      public int feedBuffer(int bytesToRead) throws IOException
      Reads next portion of data from the underlying stream to the internal buffer, updates begin and end pointers and returns number of bytes actually placed in buffer.
      Parameters:
      bytesToRead - amount of bytes to read.
      Returns:
      amount of bytes actually placed into buffer.
      Throws:
      IOException
    • addToBuffer

      public int addToBuffer(int bytesToAdd) throws IOException
      Reads next portion of data from the underlying stream and appends it to the end of data, contained in internal buffer.
      Parameters:
      bytesToAdd - amount of bytes to read.
      Returns:
      amount of bytes actually appended to buffer.
      Throws:
      IOException
    • getBufferBegin

      public int getBufferBegin()
      Returns:
      beginning index of unread data in buffer.
    • getBufferEnd

      public int getBufferEnd()
      Returns:
      index of the end of of valid unread data in buffer.
    • bufferPop

      public byte bufferPop()
      Returns the character pointed by buffer begin marker and advances it.
      Returns:
      character, pointed by buffer begin marker.
    • bufferPopArray

      public int bufferPopArray(byte[] buffer, int read) throws IOException
      Reads data from internal buffer into passed byte array and advances begin marker.
      Parameters:
      buffer - is byte array where data will be read.
      read - maximal amount of bytes to read.
      Returns:
      amount of actually read bytes.
      Throws:
      IOException - if passed buffer is too small to contain necessary amount of bytes.
    • bufferSize

      public int bufferSize()
      Returns:
      the number of bytes currently available in the buffer.
    • getBufferCapacity

      public int getBufferCapacity()
      Returns:
      the total capacity of buffer.
    • closeResource

      public void closeResource() throws IOException
      Closes stream resource. There is a difference between closing stream and closing it's resource. Several streams may have the same resource (e. g. the same file stream) and resource should be closed only after all streams using it are closed.
      Overrides:
      closeResource in class ASInFilter
      Throws:
      IOException
    • reset

      public void reset() throws IOException
      Overrides:
      reset in class ASInFilter
      Throws:
      IOException
    • concatenate

      public static byte[] concatenate(byte[] one, int lengthOne, byte[] two, int lengthTwo)
    • skip

      public int skip(int size) throws IOException
      Skips given number of decoded bytes in stream.
      Overrides:
      skip in class ASInFilter
      Parameters:
      size - is amount of bytes to skip.
      Returns:
      amount of actually skipped bytes.
      Throws:
      IOException - if stream-reading error occurs.
    • peek

      public byte peek() throws IOException
      Throws:
      IOException
    • peek

      public byte peek(int i) throws IOException
      Throws:
      IOException
    • unread

      public void unread() throws IOException
      Throws:
      IOException
    • unread

      public void unread(int i) throws IOException
      Throws:
      IOException
    • isEOF

      public boolean isEOF()
    • resetReadCounter

      public void resetReadCounter()
    • getReadCounter

      public int getReadCounter()
    • getStream

      public ASInputStream getStream(int length) throws IOException
      Gets a stream that is a piece of this stream. The next length bytes will be the data in the new stream.
      Parameters:
      length - is the length of new stream.
      Returns:
      new stream.
      Throws:
      IOException
    • getStreamUntilToken

      public ASInputStream getStreamUntilToken(byte[] token) throws IOException
      Gets a stream that is a piece of this stream. The data is taken from the current buffer position until the given token is not found.
      Parameters:
      token - is the byte array that means the end of stream.
      Returns:
      new stream.
      Throws:
      IOException