Build 1.0_r1(from source)

java.util.zip
Class Deflater

java.lang.Object
  extended by java.util.zip.Deflater

public class Deflater
extends Object

The Deflater class is used to compress bytes using the DEFLATE compression algorithm. Deflation is performed by the ZLIB compression library.

See Also:
DeflaterOutputStream, Inflater

Field Summary
static int BEST_COMPRESSION
           
static int BEST_SPEED
           
static int DEFAULT_COMPRESSION
           
static int DEFAULT_STRATEGY
           
static int DEFLATED
           
static int FILTERED
           
static int HUFFMAN_ONLY
           
static int NO_COMPRESSION
           
 
Constructor Summary
Deflater()
          Constructs a new Deflater instance with default compression level and strategy.
Deflater(int level)
          Constructs a new Deflater instance with compression level level and default compression strategy.
Deflater(int level, boolean noHeader)
          Constructs a new Deflater instance with compression level level and default compression strategy.
 
Method Summary
 int deflate(byte[] buf)
          Deflates data into the supplied buffer
 int deflate(byte[] buf, int off, int nbytes)
          Deflates data into the supplied buffer using the region from off to nbytes - 1.
 void end()
          Frees all resources held onto by this Deflater.
protected  void finalize()
          Called by the virtual machine when there are no longer any (non-weak) references to the receiver.
 void finish()
          Indicates to the Deflater that all uncompressed input has been provided to it.
 boolean finished()
          Returns whether or not all provided data has been successfully compressed.
 int getAdler()
          Returns the Adler32 checksum of uncompressed data currently read.
 long getBytesRead()
          Returns a long int of total number of bytes read by the Deflater.
 long getBytesWritten()
          Returns a long int of total number of bytes of read by the Deflater.
 int getTotalIn()
          Returns the total number of bytes of input consumed by the deflater.
 int getTotalOut()
          Returns the total number of compressed bytes output by this Deflater.
 boolean needsInput()
          Indicates whether or not all bytes of uncompressed input have been consumed by the Deflater.
 void reset()
          Resets the Deflater to accept new input without affecting any previously made settings for the compression strategy or level.
 void setDictionary(byte[] buf)
           
 void setDictionary(byte[] buf, int off, int nbytes)
          Sets the dictionary to be used for compression by this Deflater.
 void setInput(byte[] buf)
          Sets the input buffer the Deflater will use to extract uncompressed bytes for later compression.
 void setInput(byte[] buf, int off, int nbytes)
          Sets the input buffer the Deflater will use to extract uncompressed bytes for later compression.
 void setLevel(int level)
          Sets the compression level to be used when compressing data.
 void setStrategy(int strategy)
          Sets the compression strategy to be used.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BEST_COMPRESSION

public static final int BEST_COMPRESSION
See Also:
Constant Field Values

BEST_SPEED

public static final int BEST_SPEED
See Also:
Constant Field Values

DEFAULT_COMPRESSION

public static final int DEFAULT_COMPRESSION
See Also:
Constant Field Values

DEFAULT_STRATEGY

public static final int DEFAULT_STRATEGY
See Also:
Constant Field Values

DEFLATED

public static final int DEFLATED
See Also:
Constant Field Values

FILTERED

public static final int FILTERED
See Also:
Constant Field Values

HUFFMAN_ONLY

public static final int HUFFMAN_ONLY
See Also:
Constant Field Values

NO_COMPRESSION

public static final int NO_COMPRESSION
See Also:
Constant Field Values
Constructor Detail

Deflater

public Deflater()
Constructs a new Deflater instance with default compression level and strategy.


Deflater

public Deflater(int level)
Constructs a new Deflater instance with compression level level and default compression strategy. THe compression level provided must be between 0 and 9.

Parameters:
level - the compression level to use

Deflater

public Deflater(int level,
                boolean noHeader)
Constructs a new Deflater instance with compression level level and default compression strategy. If the noHeader parameter is specified then no ZLIB header will be written as part of the compressed output. The compression level specified must be between 0 and 9.

Parameters:
level - the compression level to use
noHeader - if true do not write the ZLIB header
Method Detail

deflate

public int deflate(byte[] buf)
Deflates data into the supplied buffer

Parameters:
buf - buffer to store compressed data
Returns:
number of bytes of compressed data stored

deflate

public int deflate(byte[] buf,
                   int off,
                   int nbytes)
Deflates data into the supplied buffer using the region from off to nbytes - 1.

Parameters:
buf - buffer to store compressed data
off - offset inf buf to start storing data
nbytes - number of bytes of compressed data to store in buf
Returns:
number of bytes of compressed data stored

end

public void end()
Frees all resources held onto by this Deflater. Any unused input or output is discarded. This is also called from the finalize method.

See Also:
finalize()

finalize

protected void finalize()
Description copied from class: Object
Called by the virtual machine when there are no longer any (non-weak) references to the receiver. Subclasses can use this facility to guarantee that any associated resources are cleaned up before the receiver is garbage collected. Uncaught exceptions which are thrown during the running of the method cause it to terminate immediately, but are otherwise ignored.

Note: The virtual machine assumes that the implementation in class Object is empty.

Overrides:
finalize in class Object

finish

public void finish()
Indicates to the Deflater that all uncompressed input has been provided to it.

See Also:
finished

finished

public boolean finished()
Returns whether or not all provided data has been successfully compressed.

Returns:
true if all data has been compressed, false otherwise

getAdler

public int getAdler()
Returns the Adler32 checksum of uncompressed data currently read. If a preset dictionary is used getAdler() will return the Adler32 checksum of the dictionary used.

Returns:
The Adler32 checksum of uncompressed data or preset dictionary if used
See Also:
setDictionary(byte[]), setDictionary(byte[], int, int)

getTotalIn

public int getTotalIn()
Returns the total number of bytes of input consumed by the deflater.

Returns:
number of bytes of input read.

getTotalOut

public int getTotalOut()
Returns the total number of compressed bytes output by this Deflater.

Returns:
number of compressed bytes output.

needsInput

public boolean needsInput()
Indicates whether or not all bytes of uncompressed input have been consumed by the Deflater. If needsInput() returns true setInput() must be called before deflation can continue. If all bytes of uncompressed data have been provided to the Deflater finish() must be called to ensure the compressed data is output.

Returns:
True if input is required for deflation to continue, false otherwise
See Also:
finished(), setInput(byte[]), setInput(byte[], int, int)

reset

public void reset()
Resets the Deflater to accept new input without affecting any previously made settings for the compression strategy or level. This operation must be called after finished() returns true if the Deflater is to be reused.

See Also:
finished

setDictionary

public void setDictionary(byte[] buf)

setDictionary

public void setDictionary(byte[] buf,
                          int off,
                          int nbytes)
Sets the dictionary to be used for compression by this Deflater. setDictionary() can only be called if this Deflater supports the writing of ZLIB headers. This is the default behaviour but can be overridden using Deflater(int, boolean).

See Also:
Deflater(int, boolean)

setInput

public void setInput(byte[] buf)
Sets the input buffer the Deflater will use to extract uncompressed bytes for later compression.


setInput

public void setInput(byte[] buf,
                     int off,
                     int nbytes)
Sets the input buffer the Deflater will use to extract uncompressed bytes for later compression. Input will be taken from the buffer region starting at off and ending at nbytes - 1.


setLevel

public void setLevel(int level)
Sets the compression level to be used when compressing data. The compression level must be a value between 0 and 9. This value must be set prior to calling setInput().

Parameters:
level - compression level to use
Throws:
IllegalArgumentException - If the compression level is invalid.

setStrategy

public void setStrategy(int strategy)
Sets the compression strategy to be used. The strategy must be one of FILTERED, HUFFMAN_ONLY or DEFAULT_STRATEGY.This value must be set prior to calling setInput().

Parameters:
strategy - compression strategy to use
Throws:
IllegalArgumentException - If the strategy specified is not one of FILTERED, HUFFMAN_ONLY or DEFAULT_STRATEGY.

getBytesRead

public long getBytesRead()
Returns a long int of total number of bytes read by the Deflater. This method performs the same as getTotalIn except it returns a long value instead of an integer

Returns:
bytes exactly read by deflater

getBytesWritten

public long getBytesWritten()
Returns a long int of total number of bytes of read by the Deflater. This method performs the same as getTotalOut except it returns a long value instead of an integer

Returns:
bytes exactly write by deflater

Build 1.0_r1(from source)

Please submit a feedback, bug or feature