Class BuiltInGzipDecompressor
java.lang.Object
org.apache.hadoop.io.compress.zlib.BuiltInGzipDecompressor
- All Implemented Interfaces:
Decompressor
A
Decompressor based on the popular gzip compressed file format.
http://www.gzip.org/-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe current state of the gzip decoder, external to the Inflater context. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintdecompress(byte[] b, int off, int len) Decompress the data (gzip header, deflate stream, gzip trailer) in the provided buffer.voidend()Closes the decompressor and discards any unprocessed input.booleanfinished()Returns true if the end of the gzip substream (single "member") has been reached.longReturns the total number of compressed bytes input so far, including gzip header/trailer bytes.intReturns the number of bytes remaining in the input buffer; normally called when finished() is true to determine amount of post-gzip-stream data.booleanReturnstrueif a preset dictionary is needed for decompression.booleanReturnstrueif the input data buffer is empty andDecompressor.setInput(byte[], int, int)should be called to provide more input.voidreset()Resets everything, including the input buffer, regardless of whether the current gzip substream is finished.voidsetDictionary(byte[] b, int off, int len) Sets preset dictionary for compression.voidsetInput(byte[] b, int off, int len) Sets input data for decompression.
-
Constructor Details
-
BuiltInGzipDecompressor
public BuiltInGzipDecompressor()Creates a new (pure Java) gzip decompressor.
-
-
Method Details
-
needsInput
public boolean needsInput()Description copied from interface:DecompressorReturnstrueif the input data buffer is empty andDecompressor.setInput(byte[], int, int)should be called to provide more input.- Specified by:
needsInputin interfaceDecompressor- Returns:
trueif the input data buffer is empty andDecompressor.setInput(byte[], int, int)should be called in order to provide more input.
-
setInput
public void setInput(byte[] b, int off, int len) Sets input data for decompression. This should be called if and only ifDecompressor.needsInput()returnstrueindicating that more input data is required. (Both native and non-native versions of various Decompressors require that the data passed in viab[]remain unmodified until the caller is explicitly notified--viaDecompressor.needsInput()--that the buffer may be safely modified. With this requirement, an extra buffer-copy can be avoided.)- Specified by:
setInputin interfaceDecompressor- Parameters:
b- Input dataoff- Start offsetlen- Length
-
decompress
Decompress the data (gzip header, deflate stream, gzip trailer) in the provided buffer.- Specified by:
decompressin interfaceDecompressor- Parameters:
b- Buffer for the uncompressed dataoff- Start offset of the datalen- Size of the buffer- Returns:
- the number of decompressed bytes placed into b
- Throws:
IOException- raised on errors performing I/O.
-
getBytesRead
public long getBytesRead()Returns the total number of compressed bytes input so far, including gzip header/trailer bytes.- Returns:
- the total (non-negative) number of compressed bytes read so far
-
getRemaining
public int getRemaining()Returns the number of bytes remaining in the input buffer; normally called when finished() is true to determine amount of post-gzip-stream data. Note that, other than the finished state with concatenated data after the end of the current gzip stream, this will never return a non-zero value unless called aftersetInput(byte[] b, int off, int len)and beforedecompress(byte[] b, int off, int len). (That is, afterdecompress(byte[] b, int off, int len)it always returns zero, except in finished state with concatenated data.)- Specified by:
getRemainingin interfaceDecompressor- Returns:
- the total (non-negative) number of unprocessed bytes in input
-
needsDictionary
public boolean needsDictionary()Description copied from interface:DecompressorReturnstrueif a preset dictionary is needed for decompression.- Specified by:
needsDictionaryin interfaceDecompressor- Returns:
trueif a preset dictionary is needed for decompression
-
setDictionary
public void setDictionary(byte[] b, int off, int len) Description copied from interface:DecompressorSets preset dictionary for compression. A preset dictionary is used when the history buffer can be predetermined.- Specified by:
setDictionaryin interfaceDecompressor- Parameters:
b- Dictionary data bytesoff- Start offsetlen- Length
-
finished
public boolean finished()Returns true if the end of the gzip substream (single "member") has been reached.- Specified by:
finishedin interfaceDecompressor- Returns:
trueif the end of the decompressed data output stream has been reached.
-
reset
public void reset()Resets everything, including the input buffer, regardless of whether the current gzip substream is finished.- Specified by:
resetin interfaceDecompressor
-
end
public void end()Description copied from interface:DecompressorCloses the decompressor and discards any unprocessed input.- Specified by:
endin interfaceDecompressor
-