public class LZFInputStream extends 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 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,
InputStream in) |
LZFInputStream(ChunkDecoder decoder,
InputStream in,
boolean fullReads) |
LZFInputStream(ChunkDecoder decoder,
InputStream in,
BufferRecycler bufferRecycler,
boolean fullReads) |
LZFInputStream(InputStream inputStream) |
LZFInputStream(InputStream in,
boolean fullReads) |
LZFInputStream(InputStream inputStream,
BufferRecycler bufferRecycler) |
LZFInputStream(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.
|
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(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.
|
mark, markSupported, reset
protected final ChunkDecoder _decoder
protected final BufferRecycler _recycler
protected final InputStream _inputStream
protected boolean _inputStreamClosed
protected boolean _cfgFullReads
protected byte[] _inputBuffer
protected byte[] _decodedBytes
protected int _bufferPosition
protected int _bufferLength
public LZFInputStream(InputStream inputStream) throws IOException
IOException
public LZFInputStream(ChunkDecoder decoder, InputStream in) throws IOException
IOException
public LZFInputStream(InputStream in, boolean fullReads) throws 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)IOException
public LZFInputStream(ChunkDecoder decoder, InputStream in, boolean fullReads) throws IOException
IOException
public LZFInputStream(InputStream inputStream, BufferRecycler bufferRecycler) throws IOException
IOException
public LZFInputStream(InputStream in, BufferRecycler bufferRecycler, boolean fullReads) throws 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 instancesIOException
public LZFInputStream(ChunkDecoder decoder, InputStream in, BufferRecycler bufferRecycler, boolean fullReads) throws IOException
IOException
public void setUseFullReads(boolean b)
public int available()
available
in class InputStream
public int read() throws IOException
read
in class InputStream
IOException
public int read(byte[] buffer) throws IOException
read
in class InputStream
IOException
public int read(byte[] buffer, int offset, int length) throws IOException
read
in class InputStream
IOException
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class InputStream
IOException
public long skip(long n) throws IOException
skip
in class InputStream
IOException
public 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(OutputStream out) throws 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 contentIOException
protected boolean readyBuffer() throws IOException
IOException
Copyright © 2019. All rights reserved.