org.apache.hadoop.io.compress
Class BZip2Codec

java.lang.Object
  extended by org.apache.hadoop.io.compress.BZip2Codec
All Implemented Interfaces:
Configurable, CompressionCodec, SplittableCompressionCodec

@InterfaceAudience.Public
@InterfaceStability.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.


Constructor Summary
BZip2Codec()
          Creates a new instance of BZip2Codec.
 
Method Summary
 Compressor createCompressor()
          Create a new Compressor for use by this CompressionCodec.
 Decompressor createDecompressor()
          Create a new Decompressor for use by this CompressionCodec.
 CompressionInputStream createInputStream(InputStream in)
          Create a CompressionInputStream that will read from the given input stream and return a stream for uncompressed data.
 CompressionInputStream createInputStream(InputStream in, Decompressor decompressor)
          Create a CompressionInputStream that will read from the given InputStream with the given Decompressor, and return a stream for uncompressed data.
 SplitCompressionInputStream createInputStream(InputStream seekableIn, Decompressor decompressor, long start, long end, org.apache.hadoop.io.compress.SplittableCompressionCodec.READ_MODE readMode)
          Creates CompressionInputStream to be used to read off uncompressed data in one of the two reading modes.
 CompressionOutputStream createOutputStream(OutputStream out)
          Create a CompressionOutputStream that will write to the given OutputStream.
 CompressionOutputStream createOutputStream(OutputStream out, Compressor compressor)
          Create a CompressionOutputStream that will write to the given OutputStream with the given Compressor.
 Class<? extends Compressor> getCompressorType()
          Get the type of Compressor needed by this CompressionCodec.
 Configuration getConf()
          Return the configuration used by this object.
 Class<? extends Decompressor> getDecompressorType()
          Get the type of Decompressor needed by this CompressionCodec.
 String getDefaultExtension()
          .bz2 is recognized as the default extension for compressed BZip2 files
 void setConf(Configuration conf)
          Set the configuration to be used by this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BZip2Codec

public BZip2Codec()
Creates a new instance of BZip2Codec.

Method Detail

setConf

public void setConf(Configuration conf)
Set the configuration to be used by this object.

Specified by:
setConf in interface Configurable
Parameters:
conf - the configuration object.

getConf

public Configuration getConf()
Return the configuration used by this object.

Specified by:
getConf in interface Configurable
Returns:
the configuration object used by this objec.

createOutputStream

public CompressionOutputStream createOutputStream(OutputStream out)
                                           throws IOException
Create a CompressionOutputStream that will write to the given OutputStream.

Specified by:
createOutputStream in interface CompressionCodec
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

createOutputStream

public CompressionOutputStream createOutputStream(OutputStream out,
                                                  Compressor compressor)
                                           throws IOException
Create a CompressionOutputStream that will write to the given OutputStream with the given Compressor.

Specified by:
createOutputStream in interface CompressionCodec
Parameters:
out - the location for the final output stream
compressor - compressor to use
Returns:
a stream the user can write uncompressed data to, to have it compressed
Throws:
IOException

getCompressorType

public Class<? extends Compressor> getCompressorType()
Get the type of Compressor needed by this CompressionCodec.

Specified by:
getCompressorType in interface CompressionCodec
Returns:
the type of compressor needed by this codec.

createCompressor

public Compressor createCompressor()
Create a new Compressor for use by this CompressionCodec.

Specified by:
createCompressor in interface CompressionCodec
Returns:
a new compressor for use by this codec

createInputStream

public CompressionInputStream createInputStream(InputStream in)
                                         throws IOException
Create a CompressionInputStream that will read from the given input stream and return a stream for uncompressed data.

Specified by:
createInputStream in interface CompressionCodec
Parameters:
in - the stream to read compressed bytes from
Returns:
a stream to read uncompressed bytes from
Throws:
IOException

createInputStream

public CompressionInputStream createInputStream(InputStream in,
                                                Decompressor decompressor)
                                         throws IOException
Create a CompressionInputStream that will read from the given InputStream with the given Decompressor, and return a stream for uncompressed data.

Specified by:
createInputStream in interface CompressionCodec
Parameters:
in - the stream to read compressed bytes from
decompressor - decompressor to use
Returns:
a stream to read uncompressed bytes from
Throws:
IOException

createInputStream

public SplitCompressionInputStream createInputStream(InputStream seekableIn,
                                                     Decompressor decompressor,
                                                     long start,
                                                     long end,
                                                     org.apache.hadoop.io.compress.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:
createInputStream in interface SplittableCompressionCodec
Parameters:
seekableIn - The InputStream
start - The start offset into the compressed stream
end - The end offset into the compressed stream
readMode - Controls whether progress is reported continuously or only at block boundaries.
Returns:
CompressionInputStream for BZip2 aligned at block boundaries
Throws:
IOException

getDecompressorType

public Class<? extends Decompressor> getDecompressorType()
Get the type of Decompressor needed by this CompressionCodec.

Specified by:
getDecompressorType in interface CompressionCodec
Returns:
the type of decompressor needed by this codec.

createDecompressor

public Decompressor createDecompressor()
Create a new Decompressor for use by this CompressionCodec.

Specified by:
createDecompressor in interface CompressionCodec
Returns:
a new decompressor for use by this codec

getDefaultExtension

public String getDefaultExtension()
.bz2 is recognized as the default extension for compressed BZip2 files

Specified by:
getDefaultExtension in interface CompressionCodec
Returns:
A String telling the default bzip2 file extension


Copyright © 2014 Apache Software Foundation. All Rights Reserved.