Class CachingOutputBitStream

  • All Implemented Interfaces:
    Closeable, Flushable, AutoCloseable

    public final class CachingOutputBitStream
    extends OutputBitStream
    A special output bit stream with an additional method buffer() that returns the internal buffer if the internal buffer contains all that has been written since the last call to position(0).

    This bit stream is used every time that it is necessary to cache quickly a bit stream. By sizing the buffer size appropriately, most of the times data written to the stream will be readable directly from the buffer. Remember to call OutputBitStream.align() before retrieving the buffer, or some bits might be still floating in the bit buffer.

    • Method Detail

      • buffer

        public byte[] buffer()
        Return the internal buffer, if it contains all data.

        Note that this method should always be called after an OutputBitStream.align(), or some bits might be still floating in the bit buffer.

        Returns:
        the internal buffer, if it contains the cached content written since the last call to position(0), or null.