java.lang.Object | |
↳ | java.util.zip.Deflater |
This class compresses data using the DEFLATE algorithm (see specification).
Basically this class is part of the API to the stream based ZLIB compression
library and is used as such by DeflaterOutputStream
and its
descendants.
The typical usage of a Deflater
instance outside this package
consists of a specific call to one of its constructors before being passed to
an instance of DeflaterOutputStream
.
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | BEST_COMPRESSION | Upper bound for the compression level range. | |||||||||
int | BEST_SPEED | Lower bound for compression level range. | |||||||||
int | DEFAULT_COMPRESSION | Usage of the default compression level. | |||||||||
int | DEFAULT_STRATEGY | Default value for compression strategy. | |||||||||
int | DEFLATED | Default value for compression method. | |||||||||
int | FILTERED | Possible value for compression strategy. | |||||||||
int | HUFFMAN_ONLY | Possible value for compression strategy. | |||||||||
int | NO_COMPRESSION | Possible value for compression level. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructs a new
Deflater instance with default compression
level. | |||||||||||
Constructs a new
Deflater instance with a specific compression
level. | |||||||||||
Constructs a new
Deflater instance with a specific compression
level. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Deflates the data (previously passed to
setInput ) into the
supplied buffer. | |||||||||||
Deflates data (previously passed to
setInput ) into a specific
region within the supplied buffer. | |||||||||||
Frees all resources held onto by this deflating algorithm.
| |||||||||||
Indicates to the
Deflater that all uncompressed input has been provided
to it. | |||||||||||
Returns whether or not all provided data has been successfully
compressed.
| |||||||||||
Returns the Adler32 checksum of uncompressed data currently read.
| |||||||||||
Returns a long int of total number of bytes read by the
Deflater . | |||||||||||
Returns a long int of total number of bytes of read by the
Deflater . | |||||||||||
Returns the total number of bytes of input consumed by the
Deflater . | |||||||||||
Returns the total number of compressed bytes output by this
Deflater . | |||||||||||
Counterpart to setInput().
| |||||||||||
Resets the
Deflater to accept new input without affecting any
previously made settings for the compression strategy or level. | |||||||||||
Sets the dictionary to be used for compression by this
Deflater . | |||||||||||
Sets the dictionary to be used for compression by this
Deflater . | |||||||||||
Sets the input buffer the
Deflater will use to extract uncompressed bytes
for later compression. | |||||||||||
Sets the input buffer the
Deflater will use to extract uncompressed bytes
for later compression. | |||||||||||
Sets the compression level to be used when compressing data.
| |||||||||||
Sets the compression strategy to be used.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Is called before the object's memory is being reclaimed by the VM.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class java.lang.Object
|
Upper bound for the compression level range.
Lower bound for compression level range.
Usage of the default compression level.
Default value for compression strategy.
Default value for compression method.
Possible value for compression strategy.
Possible value for compression strategy.
Possible value for compression level.
Constructs a new Deflater
instance with default compression
level. The strategy can be specified with setStrategy(int), only. A
header is added to the output by default; use constructor Deflater(level, boolean)
if you need to omit the header.
Constructs a new Deflater
instance with a specific compression
level. The strategy can be specified with setStrategy
, only. A
header is added to the output by default; use
Deflater(level, boolean)
if you need to omit the header.
level | the compression level in the range between 0 and 9. |
---|
Constructs a new Deflater
instance with a specific compression
level. If noHeader is passed as true no ZLib header is added to the
output. In a ZIP archive every entry (compressed file) comes with such a
header. The strategy can be specified with the setStrategy method, only.
level | the compression level in the range between 0 and 9. |
---|---|
noHeader | true indicates that no ZLIB header should be written. |
Deflates the data (previously passed to setInput
) into the
supplied buffer.
buf | buffer to write compressed data to. |
---|
buf
.Deflates data (previously passed to setInput
) into a specific
region within the supplied buffer.
buf | the buffer to write compressed data to. |
---|---|
off | the offset within buf at which to start writing to. |
nbytes | maximum number of bytes of compressed data to be written. |
buf
.Frees all resources held onto by this deflating algorithm. Any unused
input or output is discarded. While this method is used by finalize()
, it can be called explicitly in order to free native
resources before the next GC cycle. After end()
was called other
methods will typically throw an IllegalStateException
.
Indicates to the Deflater
that all uncompressed input has been provided
to it.
Returns whether or not all provided data has been successfully compressed.
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 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
Deflater
.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
Deflater
Returns the total number of bytes of input consumed by the Deflater
.
Returns the total number of compressed bytes output by this Deflater
.
Counterpart to setInput(). 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.
true
if input is required for deflation to continue,
false
otherwise.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.
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)
.
buf | the buffer containing the dictionary data bytes. |
---|---|
off | the offset of the data. |
nbytes | the length of the data. |
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)
.
buf | the buffer containing the dictionary data bytes. |
---|
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.
buf | the buffer containing the input data bytes. |
---|---|
off | the offset of the data. |
nbytes | the length of the data. |
Sets the input buffer the Deflater
will use to extract uncompressed bytes
for later compression.
buf | the buffer. |
---|
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().
level | compression level to use |
---|
IllegalArgumentException | If the compression level is invalid. |
---|
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().
strategy | compression strategy to use |
---|
IllegalArgumentException | If the strategy specified is not one of FILTERED, HUFFMAN_ONLY or DEFAULT_STRATEGY. |
---|
Is called before the object's memory is being reclaimed by the VM. This can only happen once the VM has detected, during a run of the garbage collector, that the object is no longer reachable by any thread of the running application.
The method can be used to free system resources or perform other cleanup
before the object is garbage collected. The default implementation of the
method is empty, which is also expected by the VM, but subclasses can
override finalize()
as required. Uncaught exceptions which are
thrown during the execution of this method cause it to terminate
immediately but are otherwise ignored.
Note that the VM does guarantee that finalize()
is called at most
once for any object, but it doesn't guarantee when (if at all) finalize()
will be called. For example, object B's finalize()
can delay the execution of object A's finalize()
method and
therefore it can delay the reclamation of A's memory. To be safe, use a
ReferenceQueue, because it provides more control
over the way the VM deals with references during garbage collection.