Assumes the stream consists of blocks of literal data and back-references (called copies) in any order. Of course the first block must be a literal block for
the scheme to work - unless the prefill method has been used to provide initial data that is never returned by read but only
used for back-references.
Subclasses must override the three-arg read method as the no-arg version delegates to it and the default implementation delegates to the no-arg
version, leading to infinite mutual recursion and a StackOverflowError otherwise.
The contract for subclasses' read implementation is:
readOneByte to access the underlying stream directly.startLiteral to tell this class about it and read the literal data using readLiteral until it
returns 0. hasMoreDataInBlock will return false before the next call to readLiteral would return 0.startBackReference to tell this class about it and read the literal data using readBackReference
until it returns 0. hasMoreDataInBlock will return false before the next call to readBackReference would return
0.-1 as this class' methods will never do so themselves.
readOneByte and readLiteral update the counter for bytes read.
| Modifier and Type | Field and Description |
|---|---|
| private int | backReferenceOffset
Offset of the current back-reference. |
| private final byte[] | buf
Buffer to write decompressed bytes to for back-references, will be three times windowSize big. |
| private long | bytesRemaining
Number of bytes still to be read from the current literal or back-reference. |
| private final CountingInputStream | in
The underlying stream to read compressed data from |
| private final byte[] | |
| private int | readIndex
Index of the next byte to be read. |
| private int | size
Uncompressed size |
| protected final ByteUtils. | supplier
Supplier that delegates to |
| private final int | windowSize
Size of the window - must be bigger than the biggest offset expected. |
| private int | writeIndex
One behind the index of the last byte in the buffer that was written, i.e. the next position to write to |
| Access | Constructor and Description |
|---|---|
| public | AbstractLZ77CompressorInputStream(final InputStream
An InputStream to read compressed data from is, final int Size of the window kept for back-references, must be bigger than the biggest offset expected. windowSize)Creates a new LZ77 input stream. |
| Modifier and Type | Method and Description |
|---|---|
| public int | available()
Overrides java. |
| public void | close()
Overrides java. Implements java. |
| public long | getCompressedCount()
Implements org. |
| public int | |
| protected final boolean | Returns: true if there is still data remaining inside the current block.Is there still data remaining inside the current block? |
| public void | prefill(final byte[]
the data to fill the window with. data)Adds some initial data to fill the window with. |
| public int | read()
Implements abstract java. |
| protected final int | Returns: number of bytes read, may be 0. Will never return -1 as EOF-detection is the responsibility of the subclassbuffer to write data to b, final int offset to start writing to off, final int maximum amount of data to read len)Reads data from the current back-reference. |
| private int | |
| protected final int | Returns: number of bytes read, may be 0. Will never return -1 as EOF-detection is the responsibility of the subclassbuffer to write data to b, final int offset to start writing to off, final int maximum amount of data to read len)Reads data from the current literal block. |
| protected final int | Returns: the byte read as value between 0 and 255 or -1 if EOF has been reached.Reads a single byte from the real input stream and ensures the data is accounted for. |
| private void | |
| protected final void | startBackReference(final int
the offset of the back-reference offset, final long the length of the back-reference length)Used by subclasses to signal the next block contains a back-reference with the given coordinates. |
| protected final void | startLiteral(final long
the length of the block length)Used by subclasses to signal the next block contains the given amount of literal data. |
| private void | |
| private void |
| backReferenceOffset | back to summary |
|---|---|
| private int backReferenceOffset Offset of the current back-reference. | |
| buf | back to summary |
|---|---|
| private final byte[] buf Buffer to write decompressed bytes to for back-references, will be three times windowSize big. Three times so we can slide the whole buffer a windowSize to the left once we've read twice windowSize and still have enough data inside of it to satisfy back-references. | |
| bytesRemaining | back to summary |
|---|---|
| private long bytesRemaining Number of bytes still to be read from the current literal or back-reference. | |
| in | back to summary |
|---|---|
| private final CountingInputStream in The underlying stream to read compressed data from | |
| oneByte | back to summary |
|---|---|
| private final byte[] oneByte | |
| readIndex | back to summary |
|---|---|
| private int readIndex Index of the next byte to be read. | |
| size | back to summary |
|---|---|
| private int size Uncompressed size | |
| supplier | back to summary |
|---|---|
| protected final ByteUtils. Supplier that delegates to | |
| windowSize | back to summary |
|---|---|
| private final int windowSize Size of the window - must be bigger than the biggest offset expected. | |
| writeIndex | back to summary |
|---|---|
| private int writeIndex One behind the index of the last byte in the buffer that was written, i.e. the next position to write to | |
| AbstractLZ77CompressorInputStream | back to summary |
|---|---|
| public AbstractLZ77CompressorInputStream(final InputStream is, final int windowSize) Creates a new LZ77 input stream.
| |
| available | back to summary |
|---|---|
| public int available() Overrides java. Doc from java. Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking, which may be 0, or 0 when end of stream is detected. The read might be on 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. Note that while some implementations of A subclass's implementation of this method may choose to throw an
| |
| close | back to summary |
|---|---|
| public void close() throws IOException Overrides java. Implements java. Doc from java. Closes this input stream and releases any system resources associated with the stream.
| |
| getCompressedCount | back to summary |
|---|---|
| public long getCompressedCount() Implements org. Doc from org. Gets the amount of raw or compressed bytes read by the stream.
| |
| getSize | back to summary |
|---|---|
| public int getSize() Gets the uncompressed size of the stream
| |
| hasMoreDataInBlock | back to summary |
|---|---|
| protected final boolean hasMoreDataInBlock() Is there still data remaining inside the current block?
| |
| prefill | back to summary |
|---|---|
| public void prefill(final byte[] data) Adds some initial data to fill the window with. This is used if the stream has been cut into blocks and back-references of one block may refer to data of the previous block(s). One such example is the LZ4 frame format using block dependency.
| |
| read | back to summary |
|---|---|
| public int read() throws IOException Implements abstract java. Doc from java. Reads the next byte of data from the input stream. The value byte is
returned as an
| |
| readBackReference | back to summary |
|---|---|
| protected final int readBackReference(final byte[] b, final int off, final int len) Reads data from the current back-reference.
| |
| readFromBuffer | back to summary |
|---|---|
| private int readFromBuffer(final byte[] b, final int off, final int len) | |
| readLiteral | back to summary |
|---|---|
| protected final int readLiteral(final byte[] b, final int off, final int len) throws IOException Reads data from the current literal block.
| |
| readOneByte | back to summary |
|---|---|
| protected final int readOneByte() throws IOException Reads a single byte from the real input stream and ensures the data is accounted for.
| |
| slideBuffer | back to summary |
|---|---|
| private void slideBuffer() | |
| startBackReference | back to summary |
|---|---|
| protected final void startBackReference(final int offset, final long length) Used by subclasses to signal the next block contains a back-reference with the given coordinates.
| |
| startLiteral | back to summary |
|---|---|
| protected final void startLiteral(final long length) Used by subclasses to signal the next block contains the given amount of literal data.
| |
| tryToCopy | back to summary |
|---|---|
| private void tryToCopy(final int bytesToCopy) | |
| tryToReadLiteral | back to summary |
|---|---|
| private void tryToReadLiteral(final int bytesToRead) throws IOException | |