org.at4j.zip.comp
Class BZip2CompressionMethod

java.lang.Object
  extended by org.at4j.zip.comp.BZip2CompressionMethod
All Implemented Interfaces:
ZipEntryCompressionMethod, ZipEntryCompressionMethodFactory

public class BZip2CompressionMethod
extends Object
implements ZipEntryCompressionMethod, ZipEntryCompressionMethodFactory

This is the "bzip2" compression method.

This class cannot be instantiated. Use the singleton instance INSTANCE instead.

Since:
1.0
Author:
Karl Gustafsson

Field Summary
static UnsignedShort CODE
          The unique code for this compression method.
static BZip2CompressionMethod INSTANCE
          Singleton instance.
static String NAME
           
static UnsignedShort VERSION_NEEDED_TO_EXTRACT
          The PK-Zip version needed to extract entries compressed with this compression method.
 
Constructor Summary
BZip2CompressionMethod()
          This creates a bzip2 compression method that will use the default block size (900k) for compression.
BZip2CompressionMethod(CompressionLevel level)
          Create a bzip2 compression method that will have the supplied compression level.
BZip2CompressionMethod(int blockSize)
          Create a bzip2 compression method that will use the supplied block size.
 
Method Summary
 BZip2CompressionMethod create(ZipGeneralPurposeBitFlags gbBitFlags)
          Create a compression method instance.
 InputStream createInputStream(InputStream is, long compressedSize, long uncompressedSize)
          Create an InputStream that clients can use to read uncompressed file data from.
 OutputStream createOutputStream(OutputStream os)
          Create an OutputStream that compresses the data written to it and writes it to the wrapped output stream.
 RandomAccess createRandomAccess(RandomAccess ra, long compressedSize, long uncompressedSize)
          This method always throws an UnsupportedOperationException.
 ZipEntryCompressionMethod createWithCompressionLevel(CompressionLevel level)
          Create a new ZipEntryCompressionMethod object that will have the supplied compression level.
 UnsignedShort getCode()
          Get the unique code that is used to identify this compression method in a Zip entry's header.
 String getName()
          Get a human-readable name for the compression method.
 UnsignedShort getVersionNeededToExtract()
          Get the PK-Zip version needed to extract Zip entries compressed by this compression method.
 boolean isRandomAccessSupported()
          This method always returns false
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CODE

public static final UnsignedShort CODE
The unique code for this compression method. The code is used in the Zip entry's header to specify the compression method that is used for compressing the entry's file data.


NAME

public static final String NAME
See Also:
Constant Field Values

VERSION_NEEDED_TO_EXTRACT

public static final UnsignedShort VERSION_NEEDED_TO_EXTRACT
The PK-Zip version needed to extract entries compressed with this compression method. See ZipEntryCompressionMethod.getVersionNeededToExtract().


INSTANCE

public static final BZip2CompressionMethod INSTANCE
Singleton instance. This is used instead of instantiating this class.

Constructor Detail

BZip2CompressionMethod

public BZip2CompressionMethod()
This creates a bzip2 compression method that will use the default block size (900k) for compression.

Instead of calling this constructor, consider using the singleton instance INSTANCE instead.


BZip2CompressionMethod

public BZip2CompressionMethod(int blockSize)
                       throws IllegalArgumentException
Create a bzip2 compression method that will use the supplied block size.

Parameters:
blockSize - The block size in hundreds of kilobytes. This number must be between 1 and 9 (inclusive).
Throws:
IllegalArgumentException - If the block size is not in the range 1 <= blockSize <= 9.

BZip2CompressionMethod

public BZip2CompressionMethod(CompressionLevel level)
Create a bzip2 compression method that will have the supplied compression level.

Parameters:
level - The compression level.
Since:
1.0.2
Method Detail

getCode

public UnsignedShort getCode()
Description copied from interface: ZipEntryCompressionMethod
Get the unique code that is used to identify this compression method in a Zip entry's header.

Specified by:
getCode in interface ZipEntryCompressionMethod
Specified by:
getCode in interface ZipEntryCompressionMethodFactory
Returns:
The compression method's unique code.

getName

public String getName()
Description copied from interface: ZipEntryCompressionMethod
Get a human-readable name for the compression method.

Specified by:
getName in interface ZipEntryCompressionMethod
Returns:
The compression method's name.

getVersionNeededToExtract

public UnsignedShort getVersionNeededToExtract()
Description copied from interface: ZipEntryCompressionMethod
Get the PK-Zip version needed to extract Zip entries compressed by this compression method.

Specified by:
getVersionNeededToExtract in interface ZipEntryCompressionMethod
Returns:
An UnsignedShort representing the version number. 10 corresponds to version 1.0, 62 to 6.2, etc.

createInputStream

public InputStream createInputStream(InputStream is,
                                     long compressedSize,
                                     long uncompressedSize)
                              throws IOException
Description copied from interface: ZipEntryCompressionMethod
Create an InputStream that clients can use to read uncompressed file data from.

Specified by:
createInputStream in interface ZipEntryCompressionMethod
Parameters:
is - An open InputStream on the compressed file data.
compressedSize - The total size of the compressed data.
uncompressedSize - The total size of the uncompressed data.
Returns:
An open InputStream containing uncompressed file data.
Throws:
IOException - On I/O errors.

createOutputStream

public OutputStream createOutputStream(OutputStream os)
                                throws IOException,
                                       UnsupportedCompressionMethodException
Description copied from interface: ZipEntryCompressionMethod
Create an OutputStream that compresses the data written to it and writes it to the wrapped output stream. This is used when building Zip files.

Specified by:
createOutputStream in interface ZipEntryCompressionMethod
Parameters:
os - The wrapped output stream.
Returns:
A compressing output stream.
Throws:
IOException - On I/O errors.
UnsupportedCompressionMethodException - If the compression method is not supported.

toString

public String toString()
Overrides:
toString in class Object

create

public BZip2CompressionMethod create(ZipGeneralPurposeBitFlags gbBitFlags)
Description copied from interface: ZipEntryCompressionMethodFactory
Create a compression method instance.

Specified by:
create in interface ZipEntryCompressionMethodFactory
Parameters:
gbBitFlags - The Zip entry's general purpose bit flags. They may contain compression algorithm parameters.
Returns:
The Zip entry compression method.

createRandomAccess

public RandomAccess createRandomAccess(RandomAccess ra,
                                       long compressedSize,
                                       long uncompressedSize)
                                throws UnsupportedOperationException
This method always throws an UnsupportedOperationException.

Specified by:
createRandomAccess in interface ZipEntryCompressionMethod
Parameters:
ra - An open random access object on the file entry's data.
compressedSize - The total size of the compressed data.
uncompressedSize - The total size of the uncompressed data.
Returns:
On open RandomAccess that can be used to read uncompressed data.
Throws:
UnsupportedOperationException - Always.

isRandomAccessSupported

public boolean isRandomAccessSupported()
This method always returns false

Specified by:
isRandomAccessSupported in interface ZipEntryCompressionMethod
Returns:
false, always.

createWithCompressionLevel

public ZipEntryCompressionMethod createWithCompressionLevel(CompressionLevel level)
Description copied from interface: ZipEntryCompressionMethod
Create a new ZipEntryCompressionMethod object that will have the supplied compression level.

The reason for this method is that it makes it easier to set a custom compression level for a compression method, without having to create a new compression method object from scratch manually.

Specified by:
createWithCompressionLevel in interface ZipEntryCompressionMethod
Parameters:
level - The compression level.
Returns:
A new compression method object. If the new object would have been created with the same settings as this object, this method may return this since ZipEntryCompressionMethod objects are immutable.