Package com.ning.compress.lzf
Class LZFCompressingInputStream
java.lang.Object
java.io.InputStream
com.ning.compress.lzf.LZFCompressingInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
Decorator
InputStream
implementation used for
reading uncompressed data
and compressing it on the fly, such that reads return compressed
data.
It is reverse of LZFInputStream
(which instead uncompresses data).- 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[]
Buffer that contains compressed data that is returned to readers.private ChunkEncoder
protected byte[]
Buffer in which uncompressed input is first read, before getting encoded in_encodedBytes
.protected final InputStream
Stream used for reading data to be compressedprotected boolean
Flag that indicates if we have already called 'inputStream.close()' (to avoid calling it multiple times)protected int
Number of bytes read from the underlying_inputStream
private final BufferRecycler
-
Constructor Summary
ConstructorsConstructorDescriptionLZFCompressingInputStream
(ChunkEncoder encoder, InputStream in) LZFCompressingInputStream
(ChunkEncoder encoder, InputStream in, BufferRecycler bufferRecycler) -
Method Summary
Modifier and TypeMethodDescriptionprivate void
int
void
close()
int
read()
int
read
(byte[] buffer) int
read
(byte[] buffer, int offset, int length) 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 just skip at most a single chunk at a timeMethods inherited from class java.io.InputStream
mark, markSupported, nullInputStream, readAllBytes, readNBytes, readNBytes, reset, skipNBytes, transferTo
-
Field Details
-
_recycler
-
_encoder
-
_inputStream
Stream used for reading data to be compressed -
_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[] _inputBufferBuffer in which uncompressed input is first read, before getting encoded in_encodedBytes
. -
_encodedBytes
protected byte[] _encodedBytesBuffer that contains compressed data that is returned to readers. -
_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 -
_readCount
protected int _readCountNumber of bytes read from the underlying_inputStream
-
-
Constructor Details
-
LZFCompressingInputStream
-
LZFCompressingInputStream
-
LZFCompressingInputStream
public LZFCompressingInputStream(ChunkEncoder encoder, InputStream in, BufferRecycler bufferRecycler)
-
-
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()- 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
-
_closeInput
- Throws:
IOException
-
skip
Overridden to just skip at most a single chunk at a time- Overrides:
skip
in classInputStream
- Throws:
IOException
-
readyBuffer
Fill the uncompressed bytes buffer by reading the underlying inputStream.- Throws:
IOException
-