java.util.zip.Deflater
java.lang.Object
None
None
New as of JDK 1.1
The Deflater class provides support for general-purpose data compression. The class uses the ZLIB compression algorithms described in RFC 1950, RFC 1951, and RFC 1952. These documents can be found at:
The Inflater class uncompresses data that has been compressed using Deflater.
The DeflaterOutputStream uses an internal Deflater to compress data. Typically, you do not need to create a Deflater; instead, you can just use an instance of one of the subclasses of DeflaterOutputStream : GZIPOutputStream or ZipOutputStream.
public class java.util.zip.Deflater extends java.lang.Object { // Constants public static final int BEST_COMPRESSION; public static final int BEST_SPEED; public static final int DEFAULT_COMPRESSION; public static final int DEFAULT_STRATEGY; public static final int DEFLATED; public static final int FILTERED; public static final int HUFFMAN_ONLY; public static final int NO_COMPRESSION; // Constructors public Deflater(); public Deflater(int level); public Deflater(int level, boolean nowrap); // Public Instance Methods public int deflate(byte[] b); public synchronized native int deflate(byte[] b, int off, int len); public synchronized native void end(); public synchronized void finish(); public synchronized boolean finished(); public synchronized native int getAdler(); public synchronized native int getTotalIn(); public synchronized native int getTotalOut(); public boolean needsInput(); public synchronized native void reset(); public void setDictionary(byte[] b); public synchronized native void setDictionary(byte[] b, int off, int len); public void setInput(byte[] b); public synchronized void setInput(byte[] b, int off, int len); public synchronized void setLevel(int level); public synchronized void setStrategy(int strategy); // Protected Instance Methods protected void finalize(); }
A constant that represents a compression level that sacrifices speed for the smallest compressed data size. The compression level for a Deflater object can be set with setLevel(), where the level ranges from 0 to 9.
A constant that represents a compression level that sacrifices compressed data size for speed. The compression level for a Deflater object can be set with setLevel(), where the level ranges from 0 to 9.
A constant that represents the default compression level.
A constant that represents the default compression strategy.
A constant that represents a compression method that uses the deflate algorithm.
A constant that represents a compression strategy that works well for small values with a random distribution.
A constant that represents a compression strategy that uses only Huffman coding.
A constant that represents a compression level that does not compress data at all. The compression level for a Deflater object can be set with setLevel(), where the level ranges from 0 to 9.
This constructor creates a Deflater that generates compressed data in the ZLIB format using the DEFAULT_COMPRESSION level.
The compression level, from 0 (NO_COMPRESSION) to 9 (BEST_COMPRESSION).
This constructor creates a Deflater that generates compressed data in the ZLIB format using the given compression level.
The compression level, from 0 (NO_COMPRESSION) to 9 (BEST_COMPRESSION).
A boolean value that specifies whether or not the ZLIB header and checksum data are omitted from the compressed data.
This constructor creates a Deflater that generates compressed data using the given compression level. If nowrap is true, the ZLIB header and checksum fields are not used, which means that the compressed data is in the format used by GZIP and PKZIP. If the parameter is false, the data is compressed into ZLIB format.
A byte array to be filled.
The number of compressed bytes actually written to the array or 0 if more data may be required.
This method compresses the data passed to setInput() and fills the given array with the compressed data. If this method returns zero, needsInput() should be called to determine whether the Deflater needs more data in its input buffer.
A byte array to be filled.
An offset into the byte array.
The number of bytes to fill.
The number of compressed bytes actually written to the array or 0 if more data may be required.
This method compresses the data passed to setInput() and writes len bytes of the compressed data into the given array, starting at off. If this method returns 0, needsInput() should be called to determine whether the Deflater needs more data in its input buffer.
This method discards any uncompressed input data and frees up internal buffers.
This method tells the Deflater that the compression should end with the data that currently occupies the input buffer.
A boolean value that indicates whether or not the end of the compressed data has been reached.
This method returns true if the last of the compressed data has been read using deflate(). Otherwise it returns false.
The Adler-32 checksum value of the uncompressed data.
This method returns an Adler32 checksum value that is calculated on the uncompressed data passed to setInput().
The total number of bytes that have been input so far.
This method returns the number of bytes that have been passed to setInput() since this Deflater was created or since reset()was last called.
The total number of bytes that have been output so far.
This method returns the number of bytes that have been read from deflate() since this Deflater was created, or since reset() was last called.
A boolean value that indicates whether or not the input buffer is empty.
This method returns true if the input buffer is empty. Otherwise it returns false.
This method resets the Deflater to the state it was in when it was created, which means that a new set of data can be compressed.
An array of byte values.
This method sets the preset dictionary for compression using the data in the given array.
public synchronized native void setDictionary(byte[] b, int off, int len)
An array of byte values.
An offset into the byte array.
The number of bytes to use.
This method sets the preset dictionary for compression using len bytes from the given array, starting from off.
An array of byte values.
This method places the contents of the given array into the input buffer of this Deflater. Use the deflate() method to compress the data and retrieve it in compressed form.
An array of byte values.
An offset into the byte array.
The number of bytes to use.
This method places len bytes from the given array, starting at off, into the input buffer of this Deflater. Use the deflate() method to compress the data and retrieve it in compressed form.
The compression level, from 0 (NO_COMPRESSION) to 9 (BEST_COMPRESSION).
If level is not valid.
This method sets the compression level of this Deflater. A value of 0 corresponds to NO_COMPRESSION. A value of 1 indicates the fastest, least space-efficient compression level (BEST_SPEED). A value of 9 indicates the slowest, most space-efficient compression level (BEST_COMPRESSION).
The compression strategy.
If strategy is not valid.
This method sets the compression strategy of this Deflater, which should be one of FILTERED, HUFFMAN_ONLY, or DEFAULT_STRATEGY.
Object.finalize()
This method calls end() when this Deflater is garbage collected.
Method |
Inherited From |
Method |
Inherited From |
---|---|---|---|
clone() |
Object |
equals(Object) |
Object |
getClass() |
Object |
hashCode() |
Object |
notify() |
Object |
notifyAll() |
Object |
toString() |
Object |
wait() |
Object |
wait(long) |
Object |
wait(long, int) |
Object |
DeflaterOutputStream, Inflater, GZIPOutputStream, ZipOutputStream