org.at4j.zip.comp
Interface ZipEntryCompressionMethod

All Known Implementing Classes:
AbstractUnsupportedCompressionMethod, BZip2CompressionMethod, Deflate64CompressionMethod, DeflatedCompressionMethod, IbmLz77CompressionMethod, IbmTerseCompressionMethod, ImplodedCompressionMethod, LzmaCompressionMethod, PKWareImplodingCompressionMethod, PpmdCompressionMethod, Reduced1CompressionMethod, Reduced2CompressionMethod, Reduced3CompressionMethod, Reduced4CompressionMethod, ShrunkCompressionMethod, StoredCompressionMethod, WavPackCompressionMethod

public interface ZipEntryCompressionMethod

This interface defines a file compression method that may occur in a Zip file. Zip compression method objects is used by the ZipFile object to handle decompression of file data, and by the ZipBuilder to handle compression of file data.

Each compression method is identified by a unique code. The ZipEntryCompressionMethodRegistry can be used to look up a compression method by its code.

Some implementations of this interface does not have any configurable internal state and can thus be used as singleton objects. All implementations are immutable.

Since:
1.0
Author:
Karl Gustafsson
See Also:
ZipEntryCompressionMethodRegistry, ZipEntryCompressionMethodFactory

Method Summary
 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)
          Open a read only random access object on the file entry's data.
 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()
          Does this compression method support read only random access on uncompressed file data?
 

Method Detail

getCode

UnsignedShort getCode()
Get the unique code that is used to identify this compression method in a Zip entry's header.

Returns:
The compression method's unique code.

getName

String getName()
Get a human-readable name for the compression method.

Returns:
The compression method's name.

getVersionNeededToExtract

UnsignedShort getVersionNeededToExtract()
Get the PK-Zip version needed to extract Zip entries compressed by this compression method.

Returns:
An UnsignedShort representing the version number. 10 corresponds to version 1.0, 62 to 6.2, etc.

createInputStream

InputStream createInputStream(InputStream is,
                              long compressedSize,
                              long uncompressedSize)
                              throws IOException,
                                     UnsupportedCompressionMethodException,
                                     ZipFileParseException
Create an InputStream that clients can use to read uncompressed file data from.

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.
UnsupportedCompressionMethodException - If the compression method is not supported.
ZipFileParseException - On parse errors.

isRandomAccessSupported

boolean isRandomAccessSupported()
Does this compression method support read only random access on uncompressed file data?

Random access is only supported by the compression methods that don't have a position-based state for the compressed data (which currently all compressing compression methods have). In other words, this is only supported if the file is stored uncompressed in the archive using the StoredCompressionMethod.

Returns:
true if the compression method supports read only random access on file data.

createRandomAccess

RandomAccess createRandomAccess(RandomAccess ra,
                                long compressedSize,
                                long uncompressedSize)
                                throws IOException,
                                       UnsupportedCompressionMethodException,
                                       UnsupportedOperationException,
                                       ZipFileParseException
Open a read only random access object on the file entry's data.

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:
IOException - On I/O errors.
UnsupportedCompressionMethodException - If the compression method is not implemented.
UnsupportedOperationException - If the compression method does not support random access to uncompressed file data.
ZipFileParseException - On parse errors.

createOutputStream

OutputStream createOutputStream(OutputStream os)
                                throws IOException,
                                       UnsupportedCompressionMethodException
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.

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.

createWithCompressionLevel

ZipEntryCompressionMethod createWithCompressionLevel(CompressionLevel level)
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.

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.
Since:
1.0.2