public class DeflatedCompressionMethod extends Object implements ZipEntryCompressionMethod
Use the getCompressionLevel()
to get the compression level for a
deflated Zip file entry.
Important note when reading deflated Zip file entries: Never try to
read more data than what is available in the stream. This sometimes
causes Java's InflaterOutputStream
to throw an
EOFException
with the message "Unexpected end of ZLIB input
stream". See this bug
report.
Modifier and Type | Field and Description |
---|---|
static UnsignedShort |
CODE
The unique code for this compression method.
|
static DeflatedCompressionMethod |
FAST_COMPRESSION
A singleton instance that uses the "fast" compression level.
|
static int |
FAST_COMPRESSION_LEVEL
The "fast" compression level.
|
static DeflatedCompressionMethod |
FASTEST_COMPRESSION
A singleton instance that uses the fastest compression level.
|
static int |
FASTEST_COMPRESSION_LEVEL
The fastest compression level.
|
static DeflatedCompressionMethod |
MAXIMUM_COMPRESSION
A singleton instance that uses the maximum compression level.
|
static int |
MAXIMUM_COMPRESSION_LEVEL
The maximum compression level.
|
static String |
NAME |
static DeflatedCompressionMethod |
NORMAL_COMPRESSION
A singleton instance that uses the "normal" compression level.
|
static int |
NORMAL_COMPRESSION_LEVEL
The "normal" compression level.
|
static UnsignedShort |
VERSION_NEEDED_TO_EXTRACT
The PK-Zip version needed to extract entries compressed with this
compression method.
|
Constructor and Description |
---|
DeflatedCompressionMethod()
Create a deflated compression method using the default compression level
(6).
|
DeflatedCompressionMethod(CompressionLevel level)
Create a deflated compression method using the specified compression
level.
|
DeflatedCompressionMethod(int compressionLevel)
Create a deflated compression method using the specified compression
level.
|
Modifier and Type | Method and Description |
---|---|
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. |
org.entityfs.RandomAccess |
createRandomAccess(org.entityfs.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.
|
int |
getCompressionLevel()
Get the compression level between 1 (fastest) and 9 (best) used by this
compression method.
|
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() |
public static final UnsignedShort CODE
public static final String NAME
public static final UnsignedShort VERSION_NEEDED_TO_EXTRACT
ZipEntryCompressionMethod.getVersionNeededToExtract()
.public static final int NORMAL_COMPRESSION_LEVEL
public static final int FAST_COMPRESSION_LEVEL
public static final int FASTEST_COMPRESSION_LEVEL
public static final int MAXIMUM_COMPRESSION_LEVEL
public static final DeflatedCompressionMethod FASTEST_COMPRESSION
public static final DeflatedCompressionMethod FAST_COMPRESSION
public static final DeflatedCompressionMethod NORMAL_COMPRESSION
public static final DeflatedCompressionMethod MAXIMUM_COMPRESSION
public DeflatedCompressionMethod()
public DeflatedCompressionMethod(int compressionLevel) throws IllegalArgumentException
compressionLevel
- The compression level, between 1
(fastest) and 9
(best compression}.IllegalArgumentException
- If the compression level is not in the
range 1 to 9 (inclusive).public DeflatedCompressionMethod(CompressionLevel level)
level
- The compression level.public UnsignedShort getCode()
ZipEntryCompressionMethod
getCode
in interface ZipEntryCompressionMethod
public String getName()
ZipEntryCompressionMethod
getName
in interface ZipEntryCompressionMethod
public UnsignedShort getVersionNeededToExtract()
ZipEntryCompressionMethod
getVersionNeededToExtract
in interface ZipEntryCompressionMethod
UnsignedShort
representing the version number. 10
corresponds to version 1.0, 62
to 6.2, etc.public int getCompressionLevel()
public InputStream createInputStream(InputStream is, long compressedSize, long uncompressedSize)
ZipEntryCompressionMethod
InputStream
that clients can use to read uncompressed
file data from.createInputStream
in interface ZipEntryCompressionMethod
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.InputStream
containing uncompressed file data.public OutputStream createOutputStream(OutputStream os) throws IOException, UnsupportedCompressionMethodException
ZipEntryCompressionMethod
OutputStream
that compresses the data written to it and
writes it to the wrapped output stream. This is used when building Zip
files.createOutputStream
in interface ZipEntryCompressionMethod
os
- The wrapped output stream.IOException
- On I/O errors.UnsupportedCompressionMethodException
- If the compression method
is not supported.public org.entityfs.RandomAccess createRandomAccess(org.entityfs.RandomAccess ra, long compressedSize, long uncompressedSize) throws UnsupportedOperationException
UnsupportedOperationException
.createRandomAccess
in interface ZipEntryCompressionMethod
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.RandomAccess
that can be used to read
uncompressed data.UnsupportedOperationException
- Always.public boolean isRandomAccessSupported()
false
isRandomAccessSupported
in interface ZipEntryCompressionMethod
false
, always.public ZipEntryCompressionMethod createWithCompressionLevel(CompressionLevel level)
ZipEntryCompressionMethod
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.
createWithCompressionLevel
in interface ZipEntryCompressionMethod
level
- The compression level.this
since ZipEntryCompressionMethod
objects are
immutable.