|
JavaTM 2 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 2 Platform Standard Ed. 6 |
|||||||||
| 上一個類別 下一個類別 | 框架 無框架 | |||||||||
| 摘要: 巢狀 | 欄位 | 建構子 | 方法 | 詳細資訊: 欄位 | 建構子 | 方法 | |||||||||
版權所有 2008 Sun Microsystems, Inc. 保留所有權利。請遵守GNU General Public License, version 2 only。