|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.util.zip.Inflater
This class provides support for general purpose decompression using popular ZLIB compression library. The ZLIB compression library was initially developed as part of the PNG graphics standard and is not protected by patents. It is fully described in the specifications at the java.util.zip package description.
The following code fragment demonstrates a trivial compression and decompression of a string using Deflater and Inflater.
// Encode a String into bytes String inputString = "blahblahblah€€"; byte[] input = inputString.getBytes("UTF-8"); // Compress the bytes byte[] output = new byte[100]; Deflater compresser = new Deflater(); compresser.setInput(input); compresser.finish(); int compressedDataLength = compresser.deflate(output); // Decompress the bytes Inflater decompresser = new Inflater(); decompresser.setInput(output, 0, compressedDataLength); byte[] result = new byte[100]; int resultLength = decompresser.inflate(result); decompresser.end(); // Decode the bytes into a String String outputString = new String(result, 0, resultLength, "UTF-8");
Deflater
Field Summary | |
private byte[] |
buf
|
private boolean |
finished
|
private int |
len
|
private boolean |
needDict
|
private int |
off
|
private long |
strm
|
Constructor Summary | |
Inflater()
Creates a new decompressor. |
|
Inflater(boolean nowrap)
Creates a new decompressor. |
Method Summary | |
void |
end()
Closes the decompressor and discards any unprocessed input. |
private static void |
end(long strm)
|
protected void |
finalize()
Closes the decompressor when garbage is collected. |
boolean |
finished()
Return true if the end of the compressed data stream has been reached. |
int |
getAdler()
Returns the ADLER-32 value of the uncompressed data. |
private static int |
getAdler(long strm)
|
int |
getRemaining()
Returns the total number of bytes remaining in the input buffer. |
int |
getTotalIn()
Returns the total number of bytes input so far. |
private static int |
getTotalIn(long strm)
|
int |
getTotalOut()
Returns the total number of bytes output so far. |
private static int |
getTotalOut(long strm)
|
int |
inflate(byte[] b)
Uncompresses bytes into specified buffer. |
int |
inflate(byte[] b,
int off,
int len)
Uncompresses bytes into specified buffer. |
private int |
inflateBytes(byte[] b,
int off,
int len)
|
private static long |
init(boolean nowrap)
|
private static void |
initIDs()
|
boolean |
needsDictionary()
Returns true if a preset dictionary is needed for decompression. |
boolean |
needsInput()
Returns true if no data remains in the input buffer. |
void |
reset()
Resets inflater so that a new set of input data can be processed. |
private static void |
reset(long strm)
|
void |
setDictionary(byte[] b)
Sets the preset dictionary to the given array of bytes. |
void |
setDictionary(byte[] b,
int off,
int len)
Sets the preset dictionary to the given array of bytes. |
private static void |
setDictionary(long strm,
byte[] b,
int off,
int len)
|
void |
setInput(byte[] b)
Sets input data for decompression. |
void |
setInput(byte[] b,
int off,
int len)
Sets input data for decompression. |
Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private long strm
private byte[] buf
private int off
private int len
private boolean finished
private boolean needDict
Constructor Detail |
public Inflater(boolean nowrap)
Note: When using the 'nowrap' option it is also necessary to provide an extra "dummy" byte as input. This is required by the ZLIB native library in order to support certain optimizations.
nowrap
- if true then support GZIP compatible compressionpublic Inflater()
Method Detail |
public void setInput(byte[] b, int off, int len)
b
- the input data bytesoff
- the start offset of the input datalen
- the length of the input dataneedsInput()
public void setInput(byte[] b)
b
- the input data bytesneedsInput()
public void setDictionary(byte[] b, int off, int len)
b
- the dictionary data bytesoff
- the start offset of the datalen
- the length of the dataneedsDictionary()
,
getAdler()
public void setDictionary(byte[] b)
b
- the dictionary data bytesneedsDictionary()
,
getAdler()
public int getRemaining()
public boolean needsInput()
public boolean needsDictionary()
setDictionary(byte[], int, int)
public boolean finished()
public int inflate(byte[] b, int off, int len) throws DataFormatException
b
- the buffer for the uncompressed dataoff
- the start offset of the datalen
- the maximum number of uncompressed bytes
DataFormatException
- if the compressed data format is invalidneedsInput()
,
needsDictionary()
public int inflate(byte[] b) throws DataFormatException
b
- the buffer for the uncompressed data
DataFormatException
- if the compressed data format is invalidneedsInput()
,
needsDictionary()
public int getAdler()
public int getTotalIn()
public int getTotalOut()
public void reset()
public void end()
protected void finalize()
finalize
in class Object
private static void initIDs()
private static long init(boolean nowrap)
private static void setDictionary(long strm, byte[] b, int off, int len)
private int inflateBytes(byte[] b, int off, int len) throws DataFormatException
DataFormatException
private static int getAdler(long strm)
private static int getTotalIn(long strm)
private static int getTotalOut(long strm)
private static void reset(long strm)
private static void end(long strm)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |