Package org.apache.hadoop.io.compress
Class BZip2Codec
java.lang.Object
org.apache.hadoop.io.compress.BZip2Codec
- All Implemented Interfaces:
Configurable,CompressionCodec,SplittableCompressionCodec
@Public
@Evolving
public class BZip2Codec
extends Object
implements Configurable, SplittableCompressionCodec
This class provides output and input streams for bzip2 compression
and decompression. It uses the native bzip2 library on the system
if possible, else it uses a pure-Java implementation of the bzip2
algorithm. The configuration parameter
io.compression.codec.bzip2.library can be used to control this
behavior.
In the pure-Java mode, the Compressor and Decompressor interfaces
are not implemented. Therefore, in that mode, those methods of
CompressionCodec which have a Compressor or Decompressor type
argument, throw UnsupportedOperationException.
Currently, support for splittability is available only in the
pure-Java mode; therefore, if a SplitCompressionInputStream is
requested, the pure-Java implementation is used, regardless of the
setting of the configuration parameter mentioned above.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.hadoop.io.compress.CompressionCodec
org.apache.hadoop.io.compress.CompressionCodec.UtilNested classes/interfaces inherited from interface org.apache.hadoop.io.compress.SplittableCompressionCodec
SplittableCompressionCodec.READ_MODE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCreate a newCompressorfor use by thisCompressionCodec.Create a newDecompressorfor use by thisCompressionCodec.Create aCompressionInputStreamthat will read from the given input stream and return a stream for uncompressed data.createInputStream(InputStream in, Decompressor decompressor) Create aCompressionInputStreamthat will read from the givenInputStreamwith the givenDecompressor, and return a stream for uncompressed data.createInputStream(InputStream seekableIn, Decompressor decompressor, long start, long end, SplittableCompressionCodec.READ_MODE readMode) Creates CompressionInputStream to be used to read off uncompressed data in one of the two reading modes. i.e.Create aCompressionOutputStreamthat will write to the givenOutputStream.createOutputStream(OutputStream out, Compressor compressor) Create aCompressionOutputStreamthat will write to the givenOutputStreamwith the givenCompressor.Class<? extends Compressor>Get the type ofCompressorneeded by thisCompressionCodec.getConf()Return the configuration used by this object.Class<? extends Decompressor>Get the type ofDecompressorneeded by thisCompressionCodec..bz2 is recognized as the default extension for compressed BZip2 filesvoidsetConf(Configuration conf) Set the configuration to be used by this object.static voidwriteHeader(OutputStream out)
-
Constructor Details
-
BZip2Codec
public BZip2Codec()Creates a new instance of BZip2Codec.
-
-
Method Details
-
setConf
Set the configuration to be used by this object.- Specified by:
setConfin interfaceConfigurable- Parameters:
conf- the configuration object.
-
getConf
Return the configuration used by this object.- Specified by:
getConfin interfaceConfigurable- Returns:
- the configuration object used by this objec.
-
createOutputStream
Create aCompressionOutputStreamthat will write to the givenOutputStream.- Specified by:
createOutputStreamin interfaceCompressionCodec- Parameters:
out- the location for the final output stream- Returns:
- a stream the user can write uncompressed data to, to have it compressed
- Throws:
IOException- raised on errors performing I/O.
-
createOutputStream
public CompressionOutputStream createOutputStream(OutputStream out, Compressor compressor) throws IOException Create aCompressionOutputStreamthat will write to the givenOutputStreamwith the givenCompressor.- Specified by:
createOutputStreamin interfaceCompressionCodec- Parameters:
out- the location for the final output streamcompressor- compressor to use- Returns:
- a stream the user can write uncompressed data to, to have it compressed
- Throws:
IOException- raised on errors performing I/O.
-
getCompressorType
Get the type ofCompressorneeded by thisCompressionCodec.- Specified by:
getCompressorTypein interfaceCompressionCodec- Returns:
- the type of compressor needed by this codec.
-
createCompressor
Create a newCompressorfor use by thisCompressionCodec.- Specified by:
createCompressorin interfaceCompressionCodec- Returns:
- a new compressor for use by this codec
-
createInputStream
Create aCompressionInputStreamthat will read from the given input stream and return a stream for uncompressed data.- Specified by:
createInputStreamin interfaceCompressionCodec- Parameters:
in- the stream to read compressed bytes from- Returns:
- a stream to read uncompressed bytes from
- Throws:
IOException- raised on errors performing I/O.
-
createInputStream
public CompressionInputStream createInputStream(InputStream in, Decompressor decompressor) throws IOException Create aCompressionInputStreamthat will read from the givenInputStreamwith the givenDecompressor, and return a stream for uncompressed data.- Specified by:
createInputStreamin interfaceCompressionCodec- Parameters:
in- the stream to read compressed bytes fromdecompressor- decompressor to use- Returns:
- a stream to read uncompressed bytes from
- Throws:
IOException- raised on errors performing I/O.
-
createInputStream
public SplitCompressionInputStream createInputStream(InputStream seekableIn, Decompressor decompressor, long start, long end, SplittableCompressionCodec.READ_MODE readMode) throws IOException Creates CompressionInputStream to be used to read off uncompressed data in one of the two reading modes. i.e. Continuous or Blocked reading modes- Specified by:
createInputStreamin interfaceSplittableCompressionCodec- Parameters:
seekableIn- The InputStreamstart- The start offset into the compressed streamend- The end offset into the compressed streamreadMode- Controls whether progress is reported continuously or only at block boundaries.decompressor- decompressor.- Returns:
- CompressionInputStream for BZip2 aligned at block boundaries
- Throws:
IOException- raised on errors performing I/O.
-
getDecompressorType
Get the type ofDecompressorneeded by thisCompressionCodec.- Specified by:
getDecompressorTypein interfaceCompressionCodec- Returns:
- the type of decompressor needed by this codec.
-
createDecompressor
Create a newDecompressorfor use by thisCompressionCodec.- Specified by:
createDecompressorin interfaceCompressionCodec- Returns:
- a new decompressor for use by this codec
-
getDefaultExtension
.bz2 is recognized as the default extension for compressed BZip2 files- Specified by:
getDefaultExtensionin interfaceCompressionCodec- Returns:
- A String telling the default bzip2 file extension
-
writeHeader
- Throws:
IOException
-