Class Bzip2Compressor
java.lang.Object
org.apache.hadoop.io.compress.bzip2.Bzip2Compressor
- All Implemented Interfaces:
Compressor
A
Compressor based on the popular
bzip2 compression algorithm.
http://www.bzip2.org/-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new compressor with a default values for the compression block size and work factor.Bzip2Compressor(int blockSize, int workFactor, int directBufferSize) Creates a new compressor using the specified block size.Bzip2Compressor(Configuration conf) Creates a new compressor, taking settings from the configuration. -
Method Summary
Modifier and TypeMethodDescriptionintcompress(byte[] b, int off, int len) Fills specified buffer with compressed data.voidend()Closes the compressor and discards any unprocessed input.voidfinish()When called, indicates that compression should end with the current contents of the input buffer.booleanfinished()Returns true if the end of the compressed data output stream has been reached.longReturns the total number of uncompressed bytes input so far.longReturns the total number of compressed bytes output so far.static StringbooleanReturns true if the input data buffer is empty and #setInput() should be called to provide more input.voidreinit(Configuration conf) Prepare the compressor to be used in a new stream with settings defined in the given Configuration.voidreset()Resets compressor so that a new set of input data can be processed.voidsetDictionary(byte[] b, int off, int len) Sets preset dictionary for compression.voidsetInput(byte[] b, int off, int len) Sets input data for compression.
-
Constructor Details
-
Bzip2Compressor
public Bzip2Compressor()Creates a new compressor with a default values for the compression block size and work factor. Compressed data will be generated in bzip2 format. -
Bzip2Compressor
Creates a new compressor, taking settings from the configuration.- Parameters:
conf- configuration.
-
Bzip2Compressor
public Bzip2Compressor(int blockSize, int workFactor, int directBufferSize) Creates a new compressor using the specified block size. Compressed data will be generated in bzip2 format.- Parameters:
blockSize- The block size to be used for compression. This is an integer from 1 through 9, which is multiplied by 100,000 to obtain the actual block size in bytes.workFactor- This parameter is a threshold that determines when a fallback algorithm is used for pathological data. It ranges from 0 to 250.directBufferSize- Size of the direct buffer to be used.
-
-
Method Details
-
reinit
Prepare the compressor to be used in a new stream with settings defined in the given Configuration. It will reset the compressor's block size and and work factor.- Specified by:
reinitin interfaceCompressor- Parameters:
conf- Configuration storing new settings
-
setInput
public void setInput(byte[] b, int off, int len) Description copied from interface:CompressorSets input data for compression. This should be called whenever #needsInput() returnstrueindicating that more input data is required.- Specified by:
setInputin interfaceCompressor- Parameters:
b- Input dataoff- Start offsetlen- Length
-
setDictionary
public void setDictionary(byte[] b, int off, int len) Description copied from interface:CompressorSets preset dictionary for compression. A preset dictionary is used when the history buffer can be predetermined.- Specified by:
setDictionaryin interfaceCompressor- Parameters:
b- Dictionary data bytesoff- Start offsetlen- Length
-
needsInput
public boolean needsInput()Description copied from interface:CompressorReturns true if the input data buffer is empty and #setInput() should be called to provide more input.- Specified by:
needsInputin interfaceCompressor- Returns:
trueif the input data buffer is empty and #setInput() should be called in order to provide more input.
-
finish
public void finish()Description copied from interface:CompressorWhen called, indicates that compression should end with the current contents of the input buffer.- Specified by:
finishin interfaceCompressor
-
finished
public boolean finished()Description copied from interface:CompressorReturns true if the end of the compressed data output stream has been reached.- Specified by:
finishedin interfaceCompressor- Returns:
trueif the end of the compressed data output stream has been reached.
-
compress
Description copied from interface:CompressorFills specified buffer with compressed data. Returns actual number of bytes of compressed data. A return value of 0 indicates that needsInput() should be called in order to determine if more input data is required.- Specified by:
compressin interfaceCompressor- Parameters:
b- Buffer for the compressed dataoff- Start offset of the datalen- Size of the buffer- Returns:
- The actual number of bytes of compressed data.
- Throws:
IOException- raised on errors performing I/O.
-
getBytesWritten
public long getBytesWritten()Returns the total number of compressed bytes output so far.- Specified by:
getBytesWrittenin interfaceCompressor- Returns:
- the total (non-negative) number of compressed bytes output so far
-
getBytesRead
public long getBytesRead()Returns the total number of uncompressed bytes input so far.- Specified by:
getBytesReadin interfaceCompressor- Returns:
- the total (non-negative) number of uncompressed bytes input so far
-
reset
public void reset()Description copied from interface:CompressorResets compressor so that a new set of input data can be processed.- Specified by:
resetin interfaceCompressor
-
end
public void end()Description copied from interface:CompressorCloses the compressor and discards any unprocessed input.- Specified by:
endin interfaceCompressor
-
getLibraryName
-