Spec-Zone .ru
спецификации, руководства, описания, API
JavaTM 2 Platform
Std. Ed. v1.3.1

java.util.zip
Class Deflater

java.lang.Object
  |
  +--java.util.zip.Deflater

public class Deflater
extends Object

This class provides support for general purpose compression using the popular ZLIB compression library. The ZLIB compression library was initially developed as part of the PNG graphics standard and is not protected by patents. It is fully described in the specifications at the java.util.zip package description.

See Also:
Inflater

Field Summary
static int BEST_COMPRESSION
          Compression level for best compression.
static int BEST_SPEED
          Compression level for fastest compression.
static int DEFAULT_COMPRESSION
          Default compression level.
static int DEFAULT_STRATEGY
          Default compression strategy.
static int DEFLATED
          Compression method for the deflate algorithm (the only one currently supported).
static int FILTERED
          Compression strategy best used for data consisting mostly of small values with a somewhat random distribution.
static int HUFFMAN_ONLY
          Compression strategy for Huffman coding only.
static int NO_COMPRESSION
          Compression level for no compression.
 
Constructor Summary
Deflater()
          Creates a new compressor with the default compression level.
Deflater(int level)
          Creates a new compressor using the specified compression level.
Deflater(int level, boolean nowrap)
          Creates a new compressor using the specified compression level.
 
Method Summary
 int deflate(byte[] b)
          Fills specified buffer with compressed data.
 int deflate(byte[] b, int off, int len)
          Fills specified buffer with compressed data.
 void end()
          Closes the compressor and discards any unprocessed input.
protected  void finalize()
          Closes the compressor when garbage is collected.
 void finish()
          When called, indicates that compression should end with the current contents of the input buffer.
 boolean finished()
          Returns true if the end of the compressed data output stream has been reached.
 int getAdler()
          Returns the ADLER-32 value of the uncompressed data.
 int getTotalIn()
          Returns the total number of bytes input so far.
 int getTotalOut()
          Returns the total number of bytes output so far.
 boolean needsInput()
          Returns true if the input data buffer is empty and setInput() should be called in order to provide more input.
 void reset()
          Resets deflater so that a new set of input data can be processed.
 void setDictionary(byte[] b)
          Sets preset dictionary for compression.
 void setDictionary(byte[] b, int off, int len)
          Sets preset dictionary for compression.
 void setInput(byte[] b)
          Sets input data for compression.
 void setInput(byte[] b, int off, int len)
          Sets input data for compression.
 void setLevel(int level)
          Sets the current compression level to the specified value.
 void setStrategy(int strategy)
          Sets the compression strategy to the specified value.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFLATED

public static final int DEFLATED
Compression method for the deflate algorithm (the only one currently supported).

NO_COMPRESSION

public static final int NO_COMPRESSION
Compression level for no compression.

BEST_SPEED

public static final int BEST_SPEED
Compression level for fastest compression.

BEST_COMPRESSION

public static final int BEST_COMPRESSION
Compression level for best compression.

DEFAULT_COMPRESSION

public static final int DEFAULT_COMPRESSION
Default compression level.

FILTERED

public static final int FILTERED
Compression strategy best used for data consisting mostly of small values with a somewhat random distribution. Forces more Huffman coding and less string matching.

HUFFMAN_ONLY

public static final int HUFFMAN_ONLY
Compression strategy for Huffman coding only.

DEFAULT_STRATEGY

public static final int DEFAULT_STRATEGY
Default compression strategy.
Constructor Detail

Deflater

public Deflater(int level,
                boolean nowrap)
Creates a new compressor using the specified compression level. If 'nowrap' is true then the ZLIB header and checksum fields will not be used in order to support the compression format used in both GZIP and PKZIP.
Parameters:
level - the compression level (0-9)
nowrap - if true then use GZIP compatible compression

Deflater

public Deflater(int level)
Creates a new compressor using the specified compression level. Compressed data will be generated in ZLIB format.
Parameters:
level - the compression level (0-9)

Deflater

public Deflater()
Creates a new compressor with the default compression level. Compressed data will be generated in ZLIB format.
Method Detail

setInput

public void setInput(byte[] b,
                     int off,
                     int len)
Sets input data for compression. This should be called whenever needsInput() returns true indicating that more input data is required.
Parameters:
b - the input data bytes
off - the start offset of the data
len - the length of the data
See Also:
needsInput()

setInput

public void setInput(byte[] b)
Sets input data for compression. This should be called whenever needsInput() returns true indicating that more input data is required.
Parameters:
b - the input data bytes
See Also:
needsInput()

setDictionary

public void setDictionary(byte[] b,
                          int off,
                          int len)
Sets preset dictionary for compression. A preset dictionary is used when the history buffer can be predetermined. When the data is later uncompressed with Inflater.inflate(), Inflater.getAdler() can be called in order to get the Adler-32 value of the dictionary required for decompression.
Parameters:
b - the dictionary data bytes
off - the start offset of the data
len - the length of the data
See Also:
Inflater.inflate(byte[], int, int), Inflater.getAdler()

setDictionary

public void setDictionary(byte[] b)
Sets preset dictionary for compression. A preset dictionary is used when the history buffer can be predetermined. When the data is later uncompressed with Inflater.inflate(), Inflater.getAdler() can be called in order to get the Adler-32 value of the dictionary required for decompression.
Parameters:
b - the dictionary data bytes
See Also:
Inflater.inflate(byte[], int, int), Inflater.getAdler()

setStrategy

public void setStrategy(int strategy)
Sets the compression strategy to the specified value.
Parameters:
strategy - the new compression strategy
Throws:
IllegalArgumentException - if the compression strategy is invalid

setLevel

public void setLevel(int level)
Sets the current compression level to the specified value.
Parameters:
level - the new compression level (0-9)
Throws:
IllegalArgumentException - if the compression level is invalid

needsInput

public boolean needsInput()
Returns true if the input data buffer is empty and setInput() should be called in order to provide more input.
Returns:
true if the input data buffer is empty and setInput() should be called in order to provide more input

finish

public void finish()
When called, indicates that compression should end with the current contents of the input buffer.

finished

public boolean finished()
Returns true if the end of the compressed data output stream has been reached.
Returns:
true if the end of the compressed data output stream has been reached

deflate

public int deflate(byte[] b,
                   int off,
                   int len)
Fills specified buffer with compressed data. Returns actual number of bytes of compressed data. A return value of 0 indicates that needsInput() should be called in order to determine if more input data is required.
Parameters:
b - the buffer for the compressed data
off - the start offset of the data
len - the maximum number of bytes of compressed data
Returns:
the actual number of bytes of compressed data

deflate

public int deflate(byte[] b)
Fills specified buffer with compressed data. Returns actual number of bytes of compressed data. A return value of 0 indicates that needsInput() should be called in order to determine if more input data is required.
Parameters:
b - the buffer for the compressed data
Returns:
the actual number of bytes of compressed data

getAdler

public int getAdler()
Returns the ADLER-32 value of the uncompressed data.
Returns:
the ADLER-32 value of the uncompressed data

getTotalIn

public int getTotalIn()
Returns the total number of bytes input so far.
Returns:
the total number of bytes input so far

getTotalOut

public int getTotalOut()
Returns the total number of bytes output so far.
Returns:
the total number of bytes output so far

reset

public void reset()
Resets deflater so that a new set of input data can be processed. Keeps current compression level and strategy settings.

end

public void end()
Closes the compressor and discards any unprocessed input. This method should be called when the compressor is no longer being used, but will also be called automatically by the finalize() method. Once this method is called, the behavior of the Deflater object is undefined.

finalize

protected void finalize()
Closes the compressor when garbage is collected.
Overrides:
finalize in class Object
Following copied from class: java.lang.Object
Throws:
Throwable - the Exception raised by this method

JavaTM 2 Platform
Std. Ed. v1.3.1

Submit a bug or feature
For further API reference and developer documentation, see Java 2 SDK SE Developer Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.

Java, Java 2D, and JDBC are trademarks or registered trademarks of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-2001 Sun Microsystems, Inc. 901 San Antonio Road
Palo Alto, California, 94303, U.S.A. All Rights Reserved.

free hit counter