Package com.ning.compress.gzip
Class GZIPUncompressor
- java.lang.Object
-
- com.ning.compress.Uncompressor
-
- com.ning.compress.gzip.GZIPUncompressor
-
public class GZIPUncompressor extends Uncompressor
Uncompressor
implementation for uncompressing GZIP encoded data in "push" mode, in which input is not read usingInputStream
but rather pushed to uncompressor in variable length chunks.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.zip.CRC32
_crc
protected byte[]
_decodeBuffer
Buffer used for data uncompressed from_inputBuffer
.protected int
_flags
Header flags read from gzip headerprotected GZIPRecycler
_gzipRecycler
protected DataHandler
_handler
Handler that will receive uncompressed data.protected int
_headerCRC
Expected CRC for header, from gzip file itself.protected java.util.zip.Inflater
_inflater
protected int
_inputChunkLength
protected BufferRecycler
_recycler
Object that handles details of buffer recyclingprotected int
_skippedBytes
Simple counter used when skipping fixed number of bytesprotected int
_state
Current decoding state, which determines meaning of following byte(s).protected boolean
_terminated
Flag set ifDataHandler
indicates that processing should be terminated.protected int
_trailerCount
Number of bytes that trailer indicates preceding data stream should have had.protected int
_trailerCRC
CRC container in trailer, should match calculated CRC over dataprotected static 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 numberprotected static int
DEFAULT_CHUNK_SIZE
Size of input chunks fed to underlying decoder.protected static int
FCOMMENT
protected static int
FEXTRA
protected static int
FHCRC
protected static int
FNAME
protected static int
GZIP_MAGIC
protected static byte
GZIP_MAGIC_0
protected static byte
GZIP_MAGIC_1
protected static int
STATE_BODY
State in which we are buffering compressed data for decompressionprotected static int
STATE_HEADER_COMMENT
protected static int
STATE_HEADER_COMP_TYPE
protected static int
STATE_HEADER_CRC0
protected static int
STATE_HEADER_CRC1
protected static int
STATE_HEADER_EXTRA0
protected static int
STATE_HEADER_EXTRA1
protected static int
STATE_HEADER_FLAGS
protected static int
STATE_HEADER_FNAME
protected static int
STATE_HEADER_SIG1
protected static int
STATE_HEADER_SKIP
protected static int
STATE_INITIAL
State in which a new compression stream can start.protected static int
STATE_TRAILER_CRC1
protected static int
STATE_TRAILER_CRC2
protected static int
STATE_TRAILER_CRC3
protected static int
STATE_TRAILER_INITIAL
protected static int
STATE_TRAILER_LEN0
protected static int
STATE_TRAILER_LEN1
protected static int
STATE_TRAILER_LEN2
protected static int
STATE_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)
void
complete()
Method called to indicate that all data to uncompress has already been fed.boolean
feedCompressedData(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 ifDataHandler
indicates 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.IOException
Description copied from class:Uncompressor
Method 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:
feedCompressedData
in 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.IOException
Description copied from class:Uncompressor
Method 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:
complete
in 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
-
-