java.util.zip
public class Deflater extends Object
Modifier and Type | Field and Description |
---|---|
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.
|
Constructor and Description |
---|
Deflater()
Creates a new deflater with default compression level.
|
Deflater(int lvl)
Creates a new deflater with given compression level.
|
Deflater(int lvl,
boolean noHeader)
Creates a new deflater with given compression level.
|
Modifier and Type | Method and Description |
---|---|
int |
deflate(byte[] output)
Deflates the current input block to the given array.
|
int |
deflate(byte[] output,
int off,
int len)
Deflates the current input block to the given array.
|
void |
end()
Deprecated.
Just clear all references to deflater instead.
|
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.
|
int |
getTotalIn()
Deprecated.
|
int |
getTotalOut()
Deprecated.
|
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[] buf,
int off,
int len)
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.
|
public static final int BEST_COMPRESSION
public static final int BEST_SPEED
public static final int DEFAULT_COMPRESSION
public static final int NO_COMPRESSION
public static final int DEFAULT_STRATEGY
public static final int FILTERED
public static final int HUFFMAN_ONLY
public static final int DEFLATED
public Deflater()
public Deflater(int lvl)
lvl
- the compression level, a value between NO_COMPRESSION
and BEST_COMPRESSION, or DEFAULT_COMPRESSION.IllegalArgumentException
- if lvl is out of range.public Deflater(int lvl, boolean noHeader)
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.IllegalArgumentException
- if lvl is out of range.public void reset()
public void end()
public int getAdler()
@Deprecated public int getTotalIn()
public long getBytesRead()
@Deprecated public int getTotalOut()
public long getBytesWritten()
protected void finalize()
finalize
in class Object
System.gc()
,
System.runFinalizersOnExit(boolean)
,
java.lang.ref
public void finish()
public boolean finished()
public boolean needsInput()
public void setInput(byte[] input)
setInput(input, 0, input.length)
.input
- the buffer containing the input data.IllegalStateException
- if the buffer was finished() or ended().public void setInput(byte[] input, int off, int len)
input
- the buffer containing the input data.off
- the start of the data.len
- the length of the data.IllegalStateException
- if the buffer was finished() or ended()
or if previous input is still pending.public void setLevel(int lvl)
lvl
- the new compression level.public void setStrategy(int stgy)
stgy
- the new compression strategy.public int deflate(byte[] output)
output
- the buffer where to write the compressed data.public int deflate(byte[] output, int off, int len)
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.IllegalStateException
- if end() was called.IndexOutOfBoundsException
- if offset and/or length
don't match the array length.public void setDictionary(byte[] dict)
setDictionary(dict, 0,
dict.length)
.dict
- the dictionary.IllegalStateException
- if setInput () or deflate ()
were already called or another dictionary was already set.public void setDictionary(byte[] buf, int off, int len)
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.