public abstract class AbstractLZ77CompressorInputStream extends CompressorInputStream implements InputStreamStatistics
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(long) to tell this class about it and read the literal data using readLiteral(byte[], int, int) until it
returns 0. hasMoreDataInBlock() will return false before the next call to readLiteral(byte[], int, int) would return 0.startBackReference(int, long) to tell this class about it and read the literal data using readBackReference(byte[], int, int)
until it returns 0. hasMoreDataInBlock() will return false before the next call to readBackReference(byte[], int, int) would return
0.-1 as this class' methods will never do so themselves.
readOneByte() and readLiteral(byte[], int, int) update the counter for bytes read.
| Constructor and Description |
|---|
AbstractLZ77CompressorInputStream(java.io.InputStream is,
int windowSize)
Creates a new LZ77 input stream.
|
| Modifier and Type | Method and Description |
|---|---|
int |
available() |
void |
close() |
long |
getCompressedCount()
Gets the amount of raw or compressed bytes read by the stream.
|
int |
getSize()
Gets the uncompressed size of the stream
|
void |
prefill(byte[] data)
Adds some initial data to fill the window with.
|
int |
read() |
getBytesRead, getCount, getUncompressedCountequals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetUncompressedCountpublic AbstractLZ77CompressorInputStream(java.io.InputStream is,
int windowSize)
is - An InputStream to read compressed data fromwindowSize - Size of the window kept for back-references, must be bigger than the biggest offset expected.java.lang.IllegalArgumentException - if windowSize is not bigger than 0public int available()
available in class java.io.InputStreampublic void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.InputStreamjava.io.IOExceptionpublic long getCompressedCount()
InputStreamStatisticsgetCompressedCount in interface InputStreamStatisticspublic int getSize()
public void prefill(byte[] data)
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.
data - the data to fill the window with.java.lang.IllegalStateException - if the stream has already started to read datapublic int read()
throws java.io.IOException
read in class java.io.InputStreamjava.io.IOExceptionCopyright © 2010 - 2024 Adobe. All Rights Reserved