Package com.ning.compress.gzip
Class GZIPUncompressor
- java.lang.Object
-
- com.ning.compress.Uncompressor
-
- com.ning.compress.gzip.GZIPUncompressor
-
public class GZIPUncompressor extends Uncompressor
Uncompressorimplementation for uncompressing GZIP encoded data in "push" mode, in which input is not read usingInputStreambut rather pushed to uncompressor in variable length chunks.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.zip.CRC32_crcprotected byte[]_decodeBufferBuffer used for data uncompressed from_inputBuffer.protected int_flagsHeader flags read from gzip headerprotected GZIPRecycler_gzipRecyclerprotected DataHandler_handlerHandler that will receive uncompressed data.protected int_headerCRCExpected CRC for header, from gzip file itself.protected java.util.zip.Inflater_inflaterprotected int_inputChunkLengthprotected BufferRecycler_recyclerObject that handles details of buffer recyclingprotected int_skippedBytesSimple counter used when skipping fixed number of bytesprotected int_stateCurrent decoding state, which determines meaning of following byte(s).protected boolean_terminatedFlag set ifDataHandlerindicates that processing should be terminated.protected int_trailerCountNumber of bytes that trailer indicates preceding data stream should have had.protected int_trailerCRCCRC container in trailer, should match calculated CRC over dataprotected static intDECODE_BUFFER_SIZEFor decoding we should use buffer that is big enough to contain typical amount of decoded data; 64k seems like a nice big numberprotected static intDEFAULT_CHUNK_SIZESize of input chunks fed to underlying decoder.protected static intFCOMMENTprotected static intFEXTRAprotected static intFHCRCprotected static intFNAMEprotected static intGZIP_MAGICprotected static byteGZIP_MAGIC_0protected static byteGZIP_MAGIC_1protected static intSTATE_BODYState in which we are buffering compressed data for decompressionprotected static intSTATE_HEADER_COMMENTprotected static intSTATE_HEADER_COMP_TYPEprotected static intSTATE_HEADER_CRC0protected static intSTATE_HEADER_CRC1protected static intSTATE_HEADER_EXTRA0protected static intSTATE_HEADER_EXTRA1protected static intSTATE_HEADER_FLAGSprotected static intSTATE_HEADER_FNAMEprotected static intSTATE_HEADER_SIG1protected static intSTATE_HEADER_SKIPprotected static intSTATE_INITIALState in which a new compression stream can start.protected static intSTATE_TRAILER_CRC1protected static intSTATE_TRAILER_CRC2protected static intSTATE_TRAILER_CRC3protected static intSTATE_TRAILER_INITIALprotected static intSTATE_TRAILER_LEN0protected static intSTATE_TRAILER_LEN1protected static intSTATE_TRAILER_LEN2protected static intSTATE_TRAILER_LEN3
-
Constructor Summary
Constructors Constructor Description GZIPUncompressor(DataHandler h)GZIPUncompressor(DataHandler h, int inputChunkLength)GZIPUncompressor(DataHandler h, int inputChunkLength, BufferRecycler bufferRecycler, GZIPRecycler gzipRecycler)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private int_handleHeader(byte[] comp, int offset, int end)private int_handleTrailer(byte[] comp, int offset, int end)protected boolean_hasFlag(int flag)protected void_reportBadHeader(byte[] comp, int nextOffset, int end, int relative)protected void_throwInternal()protected void_throwInternal(java.lang.String msg)voidcomplete()Method called to indicate that all data to uncompress has already been fed.booleanfeedCompressedData(byte[] comp, int offset, int len)Method called to feed more compressed data to be uncompressed, and sent to possible listeners.
-
-
-
Field Detail
-
GZIP_MAGIC
protected static final int GZIP_MAGIC
- See Also:
- Constant Field Values
-
GZIP_MAGIC_0
protected static final byte GZIP_MAGIC_0
- See Also:
- Constant Field Values
-
GZIP_MAGIC_1
protected static final byte GZIP_MAGIC_1
- See Also:
- Constant Field Values
-
FHCRC
protected static final int FHCRC
- See Also:
- Constant Field Values
-
FEXTRA
protected static final int FEXTRA
- See Also:
- Constant Field Values
-
FNAME
protected static final int FNAME
- See Also:
- Constant Field Values
-
FCOMMENT
protected static final int FCOMMENT
- See Also:
- Constant Field Values
-
DEFAULT_CHUNK_SIZE
protected static final int DEFAULT_CHUNK_SIZE
Size of input chunks fed to underlying decoder. Since it is not 100% clear what its effects are on- See Also:
- Constant Field Values
-
DECODE_BUFFER_SIZE
protected static final int DECODE_BUFFER_SIZE
For decoding we should use buffer that is big enough to contain typical amount of decoded data; 64k seems like a nice big number- See Also:
- Constant Field Values
-
STATE_INITIAL
protected static final int STATE_INITIAL
State in which a new compression stream can start.- See Also:
- Constant Field Values
-
STATE_HEADER_SIG1
protected static final int STATE_HEADER_SIG1
- See Also:
- Constant Field Values
-
STATE_HEADER_COMP_TYPE
protected static final int STATE_HEADER_COMP_TYPE
- See Also:
- Constant Field Values
-
STATE_HEADER_FLAGS
protected static final int STATE_HEADER_FLAGS
- See Also:
- Constant Field Values
-
STATE_HEADER_SKIP
protected static final int STATE_HEADER_SKIP
- See Also:
- Constant Field Values
-
STATE_HEADER_EXTRA0
protected static final int STATE_HEADER_EXTRA0
- See Also:
- Constant Field Values
-
STATE_HEADER_EXTRA1
protected static final int STATE_HEADER_EXTRA1
- See Also:
- Constant Field Values
-
STATE_HEADER_FNAME
protected static final int STATE_HEADER_FNAME
- See Also:
- Constant Field Values
-
STATE_HEADER_COMMENT
protected static final int STATE_HEADER_COMMENT
- See Also:
- Constant Field Values
-
STATE_HEADER_CRC0
protected static final int STATE_HEADER_CRC0
- See Also:
- Constant Field Values
-
STATE_HEADER_CRC1
protected static final int STATE_HEADER_CRC1
- See Also:
- Constant Field Values
-
STATE_TRAILER_INITIAL
protected static final int STATE_TRAILER_INITIAL
- See Also:
- Constant Field Values
-
STATE_TRAILER_CRC1
protected static final int STATE_TRAILER_CRC1
- See Also:
- Constant Field Values
-
STATE_TRAILER_CRC2
protected static final int STATE_TRAILER_CRC2
- See Also:
- Constant Field Values
-
STATE_TRAILER_CRC3
protected static final int STATE_TRAILER_CRC3
- See Also:
- Constant Field Values
-
STATE_TRAILER_LEN0
protected static final int STATE_TRAILER_LEN0
- See Also:
- Constant Field Values
-
STATE_TRAILER_LEN1
protected static final int STATE_TRAILER_LEN1
- See Also:
- Constant Field Values
-
STATE_TRAILER_LEN2
protected static final int STATE_TRAILER_LEN2
- See Also:
- Constant Field Values
-
STATE_TRAILER_LEN3
protected static final int STATE_TRAILER_LEN3
- See Also:
- Constant Field Values
-
STATE_BODY
protected static final int STATE_BODY
State in which we are buffering compressed data for decompression- See Also:
- Constant Field Values
-
_handler
protected final DataHandler _handler
Handler that will receive uncompressed data.
-
_recycler
protected final BufferRecycler _recycler
Object that handles details of buffer recycling
-
_gzipRecycler
protected final GZIPRecycler _gzipRecycler
-
_inflater
protected java.util.zip.Inflater _inflater
-
_crc
protected final java.util.zip.CRC32 _crc
-
_inputChunkLength
protected final int _inputChunkLength
-
_decodeBuffer
protected byte[] _decodeBuffer
Buffer used for data uncompressed from_inputBuffer.
-
_state
protected int _state
Current decoding state, which determines meaning of following byte(s).
-
_terminated
protected boolean _terminated
Flag set ifDataHandlerindicates that processing should be terminated.
-
_flags
protected int _flags
Header flags read from gzip header
-
_headerCRC
protected int _headerCRC
Expected CRC for header, from gzip file itself.
-
_skippedBytes
protected int _skippedBytes
Simple counter used when skipping fixed number of bytes
-
_trailerCRC
protected int _trailerCRC
CRC container in trailer, should match calculated CRC over data
-
_trailerCount
protected int _trailerCount
Number of bytes that trailer indicates preceding data stream should have had.
-
-
Constructor Detail
-
GZIPUncompressor
public GZIPUncompressor(DataHandler h)
-
GZIPUncompressor
public GZIPUncompressor(DataHandler h, int inputChunkLength)
-
GZIPUncompressor
public GZIPUncompressor(DataHandler h, int inputChunkLength, BufferRecycler bufferRecycler, GZIPRecycler gzipRecycler)
-
-
Method Detail
-
feedCompressedData
public boolean feedCompressedData(byte[] comp, int offset, int len) throws java.io.IOExceptionDescription copied from class:UncompressorMethod called to feed more compressed data to be uncompressed, and sent to possible listeners.NOTE: return value was added (from void to boolean) in 0.9.9
- Specified by:
feedCompressedDatain classUncompressor- Returns:
- True, if caller should process and feed more data; false if
caller is not interested in more data and processing should be terminated.
(and
Uncompressor.complete()should be called immediately) - Throws:
java.io.IOException
-
complete
public void complete() throws java.io.IOExceptionDescription copied from class:UncompressorMethod called to indicate that all data to uncompress has already been fed. This typically results in last block of data being uncompressed, and results being sent to listener(s); but may also throw an exception if incomplete block was passed.- Specified by:
completein classUncompressor- Throws:
java.io.IOException
-
_hasFlag
protected final boolean _hasFlag(int flag)
-
_handleHeader
private final int _handleHeader(byte[] comp, int offset, int end) throws java.io.IOException- Throws:
java.io.IOException
-
_handleTrailer
private final int _handleTrailer(byte[] comp, int offset, int end) throws java.io.IOException- Throws:
java.io.IOException
-
_throwInternal
protected void _throwInternal() throws GZIPException- Throws:
GZIPException
-
_throwInternal
protected void _throwInternal(java.lang.String msg) throws GZIPException- Throws:
GZIPException
-
_reportBadHeader
protected void _reportBadHeader(byte[] comp, int nextOffset, int end, int relative) throws GZIPException- Throws:
GZIPException
-
-