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() |
int |
getSize()
Get the uncompressed size of the stream
|
void |
prefill(byte[] data)
Adds some initial data to fill the window with.
|
int |
read() |
getBytesRead, getCount, getUncompressedCount
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getUncompressedCount
public AbstractLZ77CompressorInputStream(java.io.InputStream is, int windowSize) throws java.io.IOException
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.io.IOException
- if reading failspublic int read() throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.InputStream
java.io.IOException
public int available()
available
in class java.io.InputStream
public 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 long getCompressedCount()
getCompressedCount
in interface InputStreamStatistics
"Copyright © 2010 - 2020 Adobe Systems Incorporated. All Rights Reserved"