Package com.ning.compress.lzf
Class LZFInputStream
java.lang.Object
java.io.InputStream
com.ning.compress.lzf.LZFInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
Decorator
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.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int
Length of the current uncompressed bytes bufferprotected int
The current position (next char to output) in the uncompressed bytes buffer.protected boolean
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[]
the buffer of uncompressed bytes from which content is readprotected final ChunkDecoder
Underlying decoder in use.protected byte[]
the current buffer of compressed bytes (from which to decode)protected final InputStream
stream to be decompressedprotected boolean
Flag that indicates if we have already called 'inputStream.close()' (to avoid calling it multiple times)protected final BufferRecycler
Object that handles details of buffer recycling -
Constructor Summary
ConstructorsConstructorDescriptionLZFInputStream
(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) -
Method Summary
Modifier and TypeMethodDescriptionint
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
Method that can be called to discard any already buffered input, read from input source.Method that can be used to find underlyingInputStream
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 givenOutputStream
.protected boolean
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.Methods inherited from class java.io.InputStream
mark, markSupported, nullInputStream, readAllBytes, readNBytes, readNBytes, reset, skipNBytes, transferTo
-
Field Details
-
_decoder
Underlying decoder in use. -
_recycler
Object that handles details of buffer recycling -
_inputStream
stream to be decompressed -
_inputStreamClosed
protected boolean _inputStreamClosedFlag that indicates if we have already called 'inputStream.close()' (to avoid calling it multiple times) -
_cfgFullReads
protected boolean _cfgFullReadsFlag 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). Default is false, meaning that 'optimal' read is used. -
_inputBuffer
protected byte[] _inputBufferthe current buffer of compressed bytes (from which to decode) -
_decodedBytes
protected byte[] _decodedBytesthe buffer of uncompressed bytes from which content is read -
_bufferPosition
protected int _bufferPositionThe current position (next char to output) in the uncompressed bytes buffer. -
_bufferLength
protected int _bufferLengthLength of the current uncompressed bytes buffer
-
-
Constructor Details
-
LZFInputStream
- Throws:
IOException
-
LZFInputStream
- Throws:
IOException
-
LZFInputStream
- Parameters:
in
- Underlying input stream to usefullReads
- Whetherread(byte[])
should try to read exactly as many bytes as requested (true); or just however many happen to be available (false)- Throws:
IOException
-
LZFInputStream
- Throws:
IOException
-
LZFInputStream
- Throws:
IOException
-
LZFInputStream
public LZFInputStream(InputStream in, BufferRecycler bufferRecycler, boolean fullReads) throws IOException - Parameters:
in
- Underlying input stream to usebufferRecycler
- Buffer recycler instance, for usages where the caller manages the recycler instancesfullReads
- Whetherread(byte[])
should try to read exactly as many bytes as requested (true); or just however many happen to be available (false)- Throws:
IOException
-
LZFInputStream
public LZFInputStream(ChunkDecoder decoder, InputStream in, BufferRecycler bufferRecycler, boolean fullReads) throws IOException - Throws:
IOException
-
-
Method Details
-
setUseFullReads
public 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. -
available
public 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. Never throws an exception; returns number of bytes available without further reads from underlying source; -1 if stream has been closed, or 0 if an actual read (and possible blocking) is needed to find out.- Overrides:
available
in classInputStream
-
read
- Specified by:
read
in classInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
-
skip
Overridden to implement efficient skipping by skipping full chunks whenever possible.- Overrides:
skip
in classInputStream
- Throws:
IOException
-
getUnderlyingInputStream
Method that can be used to find underlyingInputStream
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). -
discardBuffered
public void discardBuffered()Method that can be called to discard any already buffered input, read from input source. Specialized method that only makes sense if the underlyingInputStream
can be repositioned reliably. -
readAndWrite
Convenience method that will read and uncompress all data available, and write it using givenOutputStream
. This avoids having to make an intermediate copy of uncompressed data which would be needed when doing the same manually.- Parameters:
out
- OutputStream to use for writing content- Returns:
- Number of bytes written (uncompressed)
- Throws:
IOException
-
readyBuffer
Fill the uncompressed bytes buffer by reading the underlying inputStream.- Returns:
- True if there is now at least one byte to read in the buffer; false if there is no more content to read
- Throws:
IOException
-