java.util.zip
public
class
java.util.zip.Deflater
The Deflater class is used to compress bytes using the DEFLATE compression
algorithm. Deflation is performed by the ZLIB compression library.
Summary
Constants
Public Constructors
Public Methods
Protected Methods
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait
Details
Constants
public
static
final
int
BEST_COMPRESSION
Constant Value:
9
(0x00000009)
public
static
final
int
BEST_SPEED
Constant Value:
1
(0x00000001)
public
static
final
int
DEFAULT_COMPRESSION
Constant Value:
-1
(0xffffffff)
public
static
final
int
DEFAULT_STRATEGY
Constant Value:
0
(0x00000000)
public
static
final
int
DEFLATED
Constant Value:
8
(0x00000008)
public
static
final
int
FILTERED
Constant Value:
1
(0x00000001)
public
static
final
int
HUFFMAN_ONLY
Constant Value:
2
(0x00000002)
public
static
final
int
NO_COMPRESSION
Constant Value:
0
(0x00000000)
Public Constructors
public
Deflater()
Constructs a new Deflater instance with default compression level and
strategy.
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
|
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
|
Public Methods
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
public
synchronized
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
public
synchronized
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.
public
synchronized
void
finish()
Indicates to the Deflater that all uncompressed input has been provided
to it.
public
synchronized
boolean
finished()
Returns whether or not all provided data has been successfully
compressed.
Returns
- true if all data has been compressed, false otherwise
public
synchronized
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
public
synchronized
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
public
synchronized
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
public
synchronized
int
getTotalIn()
Returns the total number of bytes of input consumed by the deflater.
Returns
- number of bytes of input read.
public
synchronized
int
getTotalOut()
Returns the total number of compressed bytes output by this Deflater.
Returns
- number of compressed bytes output.
public
synchronized
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
public
synchronized
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.
public
synchronized
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).
public
void
setDictionary(byte[] buf)
public
synchronized
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.
public
void
setInput(byte[] buf)
Sets the input buffer the Deflater will use to extract uncompressed bytes
for later compression.
public
synchronized
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 |
public
synchronized
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 |
Protected Methods
protected
void
finalize()
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.