public class Inflater extends Object
下面的代码片段展示了一个平凡的压缩和解压缩使用Deflater和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
Modifier and Type | Method and Description |
---|---|
void |
end()
关闭减压器和丢弃任何未经处理的输入。
|
protected void |
finalize()
关闭减压器当垃圾收集。
|
boolean |
finished()
如果已达到压缩数据流的结束,则返回真。
|
int |
getAdler()
返回未压缩的数据adler-32价值。
|
long |
getBytesRead()
返回到目前为止的压缩字节数的总数。
|
long |
getBytesWritten()
返回未压缩的字节总数输出为止。
|
int |
getRemaining()
返回在输入缓冲区中剩余的总字节数。
|
int |
getTotalIn()
返回到目前为止的压缩字节数的总数。
|
int |
getTotalOut()
返回未压缩的字节总数输出为止。
|
int |
inflate(byte[] b)
解压到指定的缓冲区字节。
|
int |
inflate(byte[] b, int off, int len)
解压到指定的缓冲区字节。
|
boolean |
needsDictionary()
如果解压缩所需的预置字典,则返回真。
|
boolean |
needsInput()
如果没有数据保持在输入缓冲区中,则返回真。
|
void |
reset()
将打气筒,一套新的输入数据处理。
|
void |
setDictionary(byte[] b)
将预设的字典设置为给定的字节数组。
|
void |
setDictionary(byte[] b, int off, int len)
将预设的字典设置为给定的字节数组。
|
void |
setInput(byte[] b)
设置用于减压的输入数据。
|
void |
setInput(byte[] b, int off, int len)
设置用于减压的输入数据。
|
public Inflater(boolean nowrap)
注意:使用“不换行”选项时,还必须提供一个额外的“虚拟”字节输入。这是通过为zlib本地库需要支持一定的优化。
nowrap
-如果真的那么支持gzip相容压缩
public Inflater()
public void setInput(byte[] b, int off, int len)
b
-输入数据字节
off
的起始偏移的输入数据
len
-输入数据的长度
needsInput()
public void setInput(byte[] b)
b
-输入数据字节
needsInput()
public void setDictionary(byte[] b, int off, int len)
b
-字典数据字节
off
的起始偏移量的数据
len
-数据的长度
needsDictionary()
,
getAdler()
public void setDictionary(byte[] b)
b
-字典数据字节
needsDictionary()
,
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
为未压缩的数据缓冲区
off
-数据的起始偏移量
len
-未压缩的字节数的最大值
DataFormatException
如果压缩数据格式无效
needsInput()
,
needsDictionary()
public int inflate(byte[] b) throws DataFormatException
b
为未压缩的数据缓冲区
DataFormatException
如果压缩数据格式无效
needsInput()
,
needsDictionary()
public int getAdler()
public int getTotalIn()
由于字节数可能大于integer.max_value,的getBytesRead()
方法已获得这一信息的首选手段。
public long getBytesRead()
public int getTotalOut()
由于字节数可能大于integer.max_value,的getBytesWritten()
方法已获得这一信息的首选手段。
public long getBytesWritten()
public void reset()
public void end()
protected void finalize()
finalize
方法重写,继承类
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, 2014, Oracle and/or its affiliates. All rights reserved.