實現輸入流過濾器,用於以 “deflate” 壓縮格式壓縮數據。
構造函數和說明
- DeflaterInputStream(輸入流中):使用默認壓縮器和緩衝區大小創建新的輸入流。
- DeflaterInputStream(InputStream in, Deflater defl):使用指定的壓縮器和默認緩衝區大小創建新的輸入流。
- DeflaterInputStream(InputStream in, Deflater defl, int bufLen) :使用指定的壓縮器和緩衝區大小創建新的輸入流。
方法:
- int available():到達 EOF 後返回 0,否則始終返回 1。
Syntax :public int available() throws IOException Parameters: n - number of bytes to be skipped 返回: the actual number of bytes skipped Throws: IOException
- 無效close():關閉此輸入流及其底層輸入流,丟棄任何掛起的未壓縮數據。
Syntax :public void close() throws IOException Overrides: close in class FilterInputStream Throws: IOException
- 無效標記(int limit):不支持該操作。
Syntax :public void mark(int limit) 參數: limit - maximum bytes that can be read before invalidating the position marker
- 布爾值markSupported():始終返回 false,因為此輸入流不支持 mark() 和 reset() 方法。
Syntax :public boolean markSupported() 返回: false, always
- int read():從輸入流讀取單個字節的壓縮數據。
Syntax :public int read() throws IOException 返回: a single byte of compressed data, or -1 if the end of the uncompressed input stream is reached Throws: IOException
- int 讀取(字節[] b,int 關閉,int len):將壓縮數據讀入字節數組。
Syntax :public int read(byte[] b, int off, int len) throws IOException Parameters: b - buffer into which the data is read off - starting offset of the data within b len - maximum number of compressed bytes to read into b 返回: the actual number of bytes read, or -1 if the end of the uncompressed input stream is reached Throws: IndexOutOfBoundsException IOException
- 無效reset():不支持該操作。
Syntax :public void reset() throws IOException Throws: IOException
- 長跳過(長n):跳過並丟棄輸入流中的數據。
Syntax :public long skip(long n) throws IOException 參數: n - number of bytes to be skipped 返回: the actual number of bytes skipped Throws: IOException
程序:
//Java program to illustrate DeflaterInputStream class
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.zip.DeflaterInputStream;
class DeflaterInputStreamDemo
{
public static void main(String[] args) throws IOException
{
byte b[] = new byte[10];
for (byte i = 0; i <10 ; i++)
{
b[i] = i;
}
ByteArrayInputStream bin = new ByteArrayInputStream(b);
DeflaterInputStream din = new DeflaterInputStream(bin);
//illustrating markSupported() method
System.out.println(din.markSupported());
//illustrating skip() method
din.skip(1);
//illustrating available() method
System.out.println(din.available());
//illustrating read(byte[] b,int off,int len)
byte c[] = new byte[10];
din.read(c,0,9);
for (int i = 0; i < 9; i++)
{
System.out.print(c[i]);
}
while(din.available() == 1)
{
//Reads a single byte of compressed data
System.out.print(din.read());
}
System.out.println();
System.out.println(din.available());
// illustrating close() method
din.close();
}
}
輸出:
false 1 -1009996100981029710199231224400175046-1 0
上麵的輸出表示壓縮數據。
下一篇:Java 中的 Java.util.zip.DeflaterOutputStream 類
相關用法
- Java Java.util.zip.ZipOutputStream用法及代碼示例
- Java Java.util.zip.ZipEntry用法及代碼示例
- Java Java.util.zip.GZIPInputStream用法及代碼示例
- Java Java.util.zip.InflaterOutputStream用法及代碼示例
- Java Java.util.zip.ZipInputStream用法及代碼示例
- Java Java.util.ArrayDeque.add()用法及代碼示例
- Java Java.util.ArrayDeque.addFirst()用法及代碼示例
- Java Java.util.ArrayDeque.addLast()用法及代碼示例
- Java Java.util.ArrayDeque.clear()用法及代碼示例
- Java Java.util.ArrayDeque.clone()用法及代碼示例
- Java Java.util.ArrayDeque.descendingIterator()用法及代碼示例
- Java Java.util.ArrayDeque.element()用法及代碼示例
- Java Java.util.ArrayDeque.getFirst()用法及代碼示例
- Java Java.util.ArrayDeque.getLast()用法及代碼示例
- Java Java.util.ArrayDeque.isEmpty()用法及代碼示例
- Java Java.util.ArrayDeque.iterator()用法及代碼示例
- Java Java.util.ArrayDeque.peek()用法及代碼示例
- Java Java.util.ArrayDeque.peekFirst()用法及代碼示例
- Java Java.util.ArrayDeque.peekLast()用法及代碼示例
- Java Java.util.ArrayDeque.poll()用法及代碼示例
- Java Java.util.ArrayDeque.pollFirst()用法及代碼示例
- Java Java.util.ArrayDeque.pollLast()用法及代碼示例
- Java Java.util.ArrayDeque.pop()用法及代碼示例
- Java Java.util.ArrayDeque.push()用法及代碼示例
- Java Java.util.ArrayDeque.remove()用法及代碼示例
注:本文由純淨天空篩選整理自佚名大神的英文原創作品 Java.util.zip.DeflaterInputStream class in Java。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。