java.util.zip
Class Deflater
This is the Deflater class. The deflater class compresses input
with the deflate algorithm described in RFC 1951. It has several
compression levels and three different strategies described below.
This class is not thread safe. This is inherent in the API, due
to the split of deflate and setInput.
static int | BEST_COMPRESSION - The best and slowest compression level.
|
static int | BEST_SPEED - The worst but fastest compression level.
|
static int | DEFAULT_COMPRESSION - The default compression level.
|
static int | DEFAULT_STRATEGY - The default strategy.
|
static int | DEFLATED - The compression method.
|
static int | FILTERED - This strategy will only allow longer string repetitions.
|
static int | HUFFMAN_ONLY - This strategy will not look for string repetitions at all.
|
static int | NO_COMPRESSION - This level won't compress at all but output uncompressed blocks.
|
Deflater() - Creates a new deflater with default compression level.
|
Deflater(int lvl) - Creates a new deflater with given compression level.
|
Deflater(int lvl, boolean nowrap) - Creates a new deflater with given compression level.
|
int | deflate(byte[] output) - Deflates the current input block to the given array.
|
int | deflate(byte[] output, int offset, int length) - Deflates the current input block to the given array.
|
void | end() - Frees all objects allocated by the compressor.
|
protected void | finalize() - Finalizes this object.
|
void | finish() - Finishes the deflater with the current input block.
|
boolean | finished() - Returns true iff the stream was finished and no more output bytes
are available.
|
int | getAdler() - Gets the current adler checksum of the data that was processed so
far.
|
long | getBytesRead() - Gets the number of input bytes processed so far.
|
long | getBytesWritten() - Gets the number of output bytes so far.
|
@Deprecated | int getTotalIn() - Gets the number of input bytes processed so far.
|
@Deprecated | int getTotalOut() - Gets the number of output bytes so far.
|
boolean | needsInput() - Returns true, if the input buffer is empty.
|
void | reset() - Resets the deflater.
|
void | setDictionary(byte[] dict) - Sets the dictionary which should be used in the deflate process.
|
void | setDictionary(byte[] dict, int offset, int length) - Sets the dictionary which should be used in the deflate process.
|
void | setInput(byte[] input) - Sets the data which should be compressed next.
|
void | setInput(byte[] input, int off, int len) - Sets the data which should be compressed next.
|
void | setLevel(int lvl) - Sets the compression level.
|
void | setStrategy(int stgy) - Sets the compression strategy.
|
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
BEST_COMPRESSION
public static final int BEST_COMPRESSION
The best and slowest compression level. This tries to find very
long and distant string repetitions.
BEST_SPEED
public static final int BEST_SPEED
The worst but fastest compression level.
DEFLATED
public static final int DEFLATED
The compression method. This is the only method supported so far.
There is no need to use this constant at all.
FILTERED
public static final int FILTERED
This strategy will only allow longer string repetitions. It is
useful for random data with a small character set.
HUFFMAN_ONLY
public static final int HUFFMAN_ONLY
This strategy will not look for string repetitions at all. It
only encodes with Huffman trees (which means, that more common
characters get a smaller encoding.
NO_COMPRESSION
public static final int NO_COMPRESSION
This level won't compress at all but output uncompressed blocks.
Deflater
public Deflater()
Creates a new deflater with default compression level.
Deflater
public Deflater(int lvl)
Creates a new deflater with given compression level.
lvl
- the compression level, a value between NO_COMPRESSION
and BEST_COMPRESSION, or DEFAULT_COMPRESSION.
Deflater
public Deflater(int lvl,
boolean nowrap)
Creates a new deflater with given compression level.
lvl
- the compression level, a value between NO_COMPRESSION
and BEST_COMPRESSION.nowrap
- true, iff we should suppress the deflate header at the
beginning and the adler checksum at the end of the output. This is
useful for the GZIP format.
deflate
public int deflate(byte[] output)
Deflates the current input block to the given array. It returns
the number of bytes compressed, or 0 if either
needsInput() or finished() returns true or length is zero.
output
- the buffer where to write the compressed data.
deflate
public int deflate(byte[] output,
int offset,
int length)
Deflates the current input block to the given array. It returns
the number of bytes compressed, or 0 if either
needsInput() or finished() returns true or length is zero.
output
- the buffer where to write the compressed data.offset
- the offset into the output array.length
- the maximum number of bytes that may be written.
end
public void end()
Frees all objects allocated by the compressor. There's no
reason to call this, since you can just rely on garbage
collection. Exists only for compatibility against Sun's JDK,
where the compressor allocates native memory.
If you call any method (even reset) afterwards the behaviour is
undefined.
finish
public void finish()
Finishes the deflater with the current input block. It is an error
to give more input after this method was called. This method must
be called to force all bytes to be flushed.
finished
public boolean finished()
Returns true iff the stream was finished and no more output bytes
are available.
getAdler
public int getAdler()
Gets the current adler checksum of the data that was processed so
far.
getBytesRead
public long getBytesRead()
Gets the number of input bytes processed so far.
getBytesWritten
public long getBytesWritten()
Gets the number of output bytes so far.
int getTotalIn
public @Deprecated int getTotalIn()
Gets the number of input bytes processed so far.
int getTotalOut
public @Deprecated int getTotalOut()
Gets the number of output bytes so far.
needsInput
public boolean needsInput()
Returns true, if the input buffer is empty.
You should then call setInput().
NOTE: This method can also return true when the stream
was finished.
reset
public void reset()
Resets the deflater. The deflater acts afterwards as if it was
just created with the same compression level and strategy as it
had before.
setDictionary
public void setDictionary(byte[] dict)
Sets the dictionary which should be used in the deflate process.
This call is equivalent to setDictionary(dict, 0,
dict.length)
.
IllegalStateException
- if setInput () or deflate ()
were already called or another dictionary was already set.
setDictionary
public void setDictionary(byte[] dict,
int offset,
int length)
Sets the dictionary which should be used in the deflate process.
The dictionary should be a byte array containing strings that are
likely to occur in the data which should be compressed. The
dictionary is not stored in the compressed output, only a
checksum. To decompress the output you need to supply the same
dictionary again.
dict
- the dictionary.offset
- an offset into the dictionary.length
- the length of the dictionary.
IllegalStateException
- if setInput () or deflate () were
already called or another dictionary was already set.
setInput
public void setInput(byte[] input)
Sets the data which should be compressed next. This should be only
called when needsInput indicates that more input is needed.
If you call setInput when needsInput() returns false, the
previous input that is still pending will be thrown away.
The given byte array should not be changed, before needsInput() returns
true again.
This call is equivalent to setInput(input, 0, input.length)
.
input
- the buffer containing the input data.
setInput
public void setInput(byte[] input,
int off,
int len)
Sets the data which should be compressed next. This should be
only called when needsInput indicates that more input is needed.
The given byte array should not be changed, before needsInput() returns
true again.
input
- the buffer containing the input data.off
- the start of the data.len
- the length of the data.
setLevel
public void setLevel(int lvl)
Sets the compression level. There is no guarantee of the exact
position of the change, but if you call this when needsInput is
true the change of compression level will occur somewhere near
before the end of the so far given input.
lvl
- the new compression level.
setStrategy
public void setStrategy(int stgy)
Sets the compression strategy. Strategy is one of
DEFAULT_STRATEGY, HUFFMAN_ONLY and FILTERED. For the exact
position where the strategy is changed, the same as for
setLevel() applies.
stgy
- the new compression strategy.
Deflater.java - Compress a data stream
Copyright (C) 1999, 2000, 2001, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version.