public class LZFInputStream
extends java.io.InputStream
InputStream
implementation used for reading compressed data
and uncompressing it on the fly, such that reads return uncompressed
data. Its direct counterpart is LZFOutputStream
; but there is
also LZFCompressingInputStream
which does reverse of this class.LZFFileInputStream
,
LZFCompressingInputStream
Modifier and Type | Field and Description |
---|---|
protected int |
_bufferLength
Length of the current uncompressed bytes buffer
|
protected int |
_bufferPosition
The current position (next char to output) in the uncompressed bytes buffer.
|
protected boolean |
_cfgFullReads
Flag that indicates whether we force full reads (reading of as many
bytes as requested), or 'optimal' reads (up to as many as available,
but at least one).
|
protected byte[] |
_decodedBytes
the buffer of uncompressed bytes from which content is read
|
protected ChunkDecoder |
_decoder
Underlying decoder in use.
|
protected byte[] |
_inputBuffer
the current buffer of compressed bytes (from which to decode)
|
protected java.io.InputStream |
_inputStream
stream to be decompressed
|
protected boolean |
_inputStreamClosed
Flag that indicates if we have already called 'inputStream.close()'
(to avoid calling it multiple times)
|
protected BufferRecycler |
_recycler
Object that handles details of buffer recycling
|
Constructor and Description |
---|
LZFInputStream(ChunkDecoder decoder,
java.io.InputStream in) |
LZFInputStream(ChunkDecoder decoder,
java.io.InputStream in,
boolean fullReads) |
LZFInputStream(ChunkDecoder decoder,
java.io.InputStream in,
BufferRecycler bufferRecycler,
boolean fullReads) |
LZFInputStream(java.io.InputStream inputStream) |
LZFInputStream(java.io.InputStream in,
boolean fullReads) |
LZFInputStream(java.io.InputStream inputStream,
BufferRecycler bufferRecycler) |
LZFInputStream(java.io.InputStream in,
BufferRecycler bufferRecycler,
boolean fullReads) |
Modifier and Type | Method and Description |
---|---|
int |
available()
Method is overridden to report number of bytes that can now be read
from decoded data buffer, without reading bytes from the underlying
stream.
|
void |
close() |
void |
discardBuffered()
Method that can be called to discard any already buffered input, read
from input source.
|
java.io.InputStream |
getUnderlyingInputStream()
Method that can be used to find underlying
InputStream that
we read from to get LZF encoded data to decode. |
int |
read() |
int |
read(byte[] buffer) |
int |
read(byte[] buffer,
int offset,
int length) |
int |
readAndWrite(java.io.OutputStream out)
Convenience method that will read and uncompress all data available,
and write it using given
OutputStream . |
protected boolean |
readyBuffer()
Fill the uncompressed bytes buffer by reading the underlying inputStream.
|
void |
setUseFullReads(boolean b)
Method that can be used define whether reads should be "full" or
"optimal": former means that full compressed blocks are read right
away as needed, optimal that only smaller chunks are read at a time,
more being read as needed.
|
long |
skip(long n)
Overridden to implement efficient skipping by skipping full chunks whenever
possible.
|
protected final ChunkDecoder _decoder
protected final BufferRecycler _recycler
protected final java.io.InputStream _inputStream
protected boolean _inputStreamClosed
protected boolean _cfgFullReads
protected byte[] _inputBuffer
protected byte[] _decodedBytes
protected int _bufferPosition
protected int _bufferLength
public LZFInputStream(java.io.InputStream inputStream) throws java.io.IOException
java.io.IOException
public LZFInputStream(ChunkDecoder decoder, java.io.InputStream in) throws java.io.IOException
java.io.IOException
public LZFInputStream(java.io.InputStream in, boolean fullReads) throws java.io.IOException
in
- Underlying input stream to usefullReads
- Whether read(byte[])
should try to read exactly
as many bytes as requested (true); or just however many happen to be
available (false)java.io.IOException
public LZFInputStream(ChunkDecoder decoder, java.io.InputStream in, boolean fullReads) throws java.io.IOException
java.io.IOException
public LZFInputStream(java.io.InputStream inputStream, BufferRecycler bufferRecycler) throws java.io.IOException
java.io.IOException
public LZFInputStream(java.io.InputStream in, BufferRecycler bufferRecycler, boolean fullReads) throws java.io.IOException
in
- Underlying input stream to usefullReads
- Whether read(byte[])
should try to read exactly
as many bytes as requested (true); or just however many happen to be
available (false)bufferRecycler
- Buffer recycler instance, for usages where the
caller manages the recycler instancesjava.io.IOException
public LZFInputStream(ChunkDecoder decoder, java.io.InputStream in, BufferRecycler bufferRecycler, boolean fullReads) throws java.io.IOException
java.io.IOException
public void setUseFullReads(boolean b)
public int available()
available
in class java.io.InputStream
public int read() throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
public int read(byte[] buffer) throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
public int read(byte[] buffer, int offset, int length) 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 long skip(long n) throws java.io.IOException
skip
in class java.io.InputStream
java.io.IOException
public java.io.InputStream getUnderlyingInputStream()
InputStream
that
we read from to get LZF encoded data to decode.
Will never return null; although underlying stream may be closed
(if this stream has been closed).public void discardBuffered()
InputStream
can be repositioned reliably.public int readAndWrite(java.io.OutputStream out) throws java.io.IOException
OutputStream
. This avoids having to
make an intermediate copy of uncompressed data which would be needed
when doing the same manually.out
- OutputStream to use for writing contentjava.io.IOException
protected boolean readyBuffer() throws java.io.IOException
java.io.IOException