|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
java.lang.Objectjava.util.zip.Inflater
public class Inflater
此类使用流行的 ZLIB 压缩程序库为通用解压缩提供支持。ZLIB 压缩程序库最初是作为 PNG 图形标准的一部分开发的,不受专利的保护。有关该规范的完整描述,请参见 java.util.zip 包描述。
以下代码片段演示使用 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| 构造方法摘要 | |
|---|---|
Inflater()
创建新的解压缩器。 |
|
Inflater(boolean nowrap)
创建新的解压缩器。 |
|
| 方法摘要 | |
|---|---|
void |
end()
关闭解压缩器并放弃所有未处理的输入。 |
protected void |
finalize()
回收垃圾时关闭解压缩器。 |
boolean |
finished()
如果已到达压缩数据流的结尾,则返回 true。 |
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()
如果解压缩需要预置字典,则返回 true。 |
boolean |
needsInput()
如果输入缓冲区中没有剩余数据,则返回 true。 |
void |
reset()
重置 inflater 以处理新的输入数据集。 |
void |
setDictionary(byte[] b)
为给定字节的数组设置预置字典。 |
void |
setDictionary(byte[] b,
int off,
int len)
为给定的字节数组设置预置字典。 |
void |
setInput(byte[] b)
为解压缩设置输入数据。 |
void |
setInput(byte[] b,
int off,
int len)
为解压缩设置输入数据。 |
| 从类 java.lang.Object 继承的方法 |
|---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| 构造方法详细信息 |
|---|
public Inflater(boolean nowrap)
注:使用 'nowrap' 选项时,还需要提供额外的 "dummy" 字节作为输入。当 ZLIB 本机库需要支持某些优化时,这是必需的。
nowrap - 如果为 true,则支持 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()
Object 中的 finalize
|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
版权所有 2007 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策。