| 
JavaTM 2 Platform Standard Ed. 5.0  | 
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
java.lang.Objectjava.util.zip.Deflater
public class Deflater
此类使用流行的 ZLIB 压缩程序库为通用压缩提供支持。ZLIB 压缩程序库最初是作为 PNG 图形标准的一部分开发的,不受专利的保护。有关该规范的完整描述,请参见 java.util.zip 包描述。
以下代码片段演示使用 Deflater 和 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");
 
Inflater| 字段摘要 | |
|---|---|
static int | 
BEST_COMPRESSION
最佳压缩的压缩级别。  | 
static int | 
BEST_SPEED
最快压缩的压缩级别。  | 
static int | 
DEFAULT_COMPRESSION
默认压缩级别。  | 
static int | 
DEFAULT_STRATEGY
默认压缩策略。  | 
static int | 
DEFLATED
deflate 算法(当前支持的惟一算法)的压缩方法。  | 
static int | 
FILTERED
最适用于主要由小值组成并具有某种程度随意分布的数据的压缩策略。  | 
static int | 
HUFFMAN_ONLY
仅适用于 Huffman 编码的压缩策略。  | 
static int | 
NO_COMPRESSION
无压缩的压缩级别。  | 
| 构造方法摘要 | |
|---|---|
Deflater()
使用默认压缩级别创建新的压缩器。  | 
|
Deflater(int level)
使用指定压缩级别创建新的压缩器。  | 
|
Deflater(int level,
         boolean nowrap)
使用指定压缩级别创建新的压缩器。  | 
|
| 方法摘要 | |
|---|---|
 int | 
deflate(byte[] b)
使用压缩数据填充指定缓冲区。  | 
 int | 
deflate(byte[] b,
        int off,
        int len)
使用压缩数据填充指定缓冲区。  | 
 void | 
end()
关闭解压缩器并放弃所有未处理的输入。  | 
protected  void | 
finalize()
回收垃圾时关闭压缩器。  | 
 void | 
finish()
调用时,指示压缩应当以输入缓冲区的当前内容结尾。  | 
 boolean | 
finished()
如果已到达压缩数据输出流的结尾,则返回 true。  | 
 int | 
getAdler()
返回未压缩数据的 ADLER-32 值。  | 
 long | 
getBytesRead()
返回到目前为止输入未压缩字节的总数。  | 
 long | 
getBytesWritten()
返回到目前为止输出压缩字节的总数。  | 
 int | 
getTotalIn()
返回到目前为止输入未压缩字节的总数。  | 
 int | 
getTotalOut()
返回到目前为止输出压缩字节的总数。  | 
 boolean | 
needsInput()
如果输入数据缓冲区为空,并且应调用 setInput() 以提供更多输入,则返回 true。  | 
 void | 
reset()
重置 deflater 以处理新的输入数据集合。  | 
 void | 
setDictionary(byte[] b)
为压缩预置字典。  | 
 void | 
setDictionary(byte[] b,
              int off,
              int len)
为压缩设置预置字典。  | 
 void | 
setInput(byte[] b)
为压缩设置输入数据。  | 
 void | 
setInput(byte[] b,
         int off,
         int len)
为压缩设置输入数据。  | 
 void | 
setLevel(int level)
将当前压缩级别设置为指定值。  | 
 void | 
setStrategy(int strategy)
将压缩策略设置为指定值。  | 
| 从类 java.lang.Object 继承的方法 | 
|---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
| 字段详细信息 | 
|---|
public static final int DEFLATED
public static final int NO_COMPRESSION
public static final int BEST_SPEED
public static final int BEST_COMPRESSION
public static final int DEFAULT_COMPRESSION
public static final int FILTERED
public static final int HUFFMAN_ONLY
public static final int DEFAULT_STRATEGY
| 构造方法详细信息 | 
|---|
public Deflater(int level,
                boolean nowrap)
level - 压缩级别 (0-9)nowrap - 如果为 true ,则使用 GZIP 兼容的压缩public Deflater(int level)
level - 压缩级别 (0-9)public Deflater()
| 方法详细信息 | 
|---|
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 - 数据的长度Inflater.inflate(byte[], int, int), 
Inflater.getAdler()public void setDictionary(byte[] b)
b - 字典数据字节Inflater.inflate(byte[], int, int), 
Inflater.getAdler()public void setStrategy(int strategy)
strategy - 新的压缩策略
IllegalArgumentException - 如果压缩策略无效public void setLevel(int level)
level - 新的压缩级别 (0-9)
IllegalArgumentException - 如果压缩级别无效public boolean needsInput()
public void finish()
public boolean finished()
public int deflate(byte[] b,
                   int off,
                   int len)
b - 压缩数据的缓冲区off - 数据的初始偏移量len - 压缩数据的最大字节数
public int deflate(byte[] b)
b - 压缩数据的缓冲区
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 2 Platform Standard Ed. 5.0  | 
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
版权所有 2004 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策。