public class Inflater extends Object
The following code fragment demonstrates a trivial compression and decompression of a string using Deflater and Inflater.
try { // 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"); } catch(java.io.UnsupportedEncodingException ex) { // handle } catch (java.util.zip.DataFormatException ex) { // handle }
Deflater
Constructor and Description |
---|
Inflater()
Creates a new decompressor.
|
Inflater(boolean nowrap)
Creates a new decompressor.
|
Modifier and Type | Method and Description |
---|---|
void |
end()
Closes the decompressor and discards any unprocessed input.
|
protected void |
finalize()
Closes the decompressor when garbage is collected.
|
boolean |
finished()
Returns true if the end of the compressed data stream has been
reached.
|
int |
getAdler()
Returns the ADLER-32 value of the uncompressed data.
|
long |
getBytesRead()
Returns the total number of compressed bytes input so far.
|
long |
getBytesWritten()
Returns the total number of uncompressed bytes output so far.
|
int |
getRemaining()
Returns the total number of bytes remaining in the input buffer.
|
int |
getTotalIn()
Returns the total number of compressed bytes input so far.
|
int |
getTotalOut()
Returns the total number of uncompressed bytes output so far.
|
int |
inflate(byte[] b)
Uncompresses bytes into specified buffer.
|
int |
inflate(byte[] b,
int off,
int len)
Uncompresses bytes into specified buffer.
|
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.
|
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.
|
void |
setInput(byte[] b)
Sets input data for decompression.
|
void |
setInput(byte[] b,
int off,
int len)
Sets input data for decompression.
|
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()
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 bytesDataFormatException
- if the compressed data format is invalidneedsInput()
,
needsDictionary()
public int inflate(byte[] b) throws DataFormatException
b
- the buffer for the uncompressed dataDataFormatException
- if the compressed data format is invalidneedsInput()
,
needsDictionary()
public int getAdler()
public int getTotalIn()
Since the number of bytes may be greater than
Integer.MAX_VALUE, the getBytesRead()
method is now
the preferred means of obtaining this information.
public long getBytesRead()
public int getTotalOut()
Since the number of bytes may be greater than
Integer.MAX_VALUE, the getBytesWritten()
method is now
the preferred means of obtaining this information.
public long getBytesWritten()
public void reset()
public void end()
protected void finalize()
finalize
in class Object
WeakReference
,
PhantomReference
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2016, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.