Class ASBufferedInFilter

    • Method Detail

      • initialize

        public void initialize()
                        throws IOException
        This method should be called before using ASBufferedInFilter as buffered stream.
        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
      • 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.
      • 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