此类实现一个输出流过滤器,用于解压缩以 “deflate” 压缩格式存储的数据。
构造函数
- InflaterOutputStream(输出流输出):创建具有默认解压缩器和缓冲区大小的新输出流。
- InflaterOutputStream(OutputStream out, Inflater infl):使用指定的解压缩器和默认缓冲区大小创建新的输出流。
- InflaterOutputStream(OutputStream out, Inflater infl, int bufLen):使用指定的解压缩器和缓冲区大小创建新的输出流。
方法:
- 无效close():将任何剩余的未压缩数据写入输出流并关闭底层输出流。
Syntax : public void close() throws IOException Overrides: close in class FilterOutputStream Throws: IOException
- 无效finish():完成将未压缩数据写入输出流,而不关闭底层流。
Syntax :public void finish() throws IOException Throws: IOException
- 无效flush():刷新此输出流,强制写入任何挂起的缓冲输出字节。
Syntax :public void flush() throws IOException Overrides: flush in class FilterOutputStream Throws: IOException
- void write(byte[] b, int off, int len):将字节数组写入未压缩的输出流。
Syntax :public void write(byte[] b, int off, int len) throws IOException Overrides: write in class FilterOutputStream Parameters: b - buffer containing compressed data to decompress and write to the output stream off - starting offset of the compressed data within b len - number of bytes to decompress from b Throws: IndexOutOfBoundsException IOException NullPointerException ZipException
- 无效写入(int b):将一个字节写入未压缩的输出流。
Syntax :public void write(int b) throws IOException Parameters: b - a single byte of compressed data to decompress and write to the output stream Throws: IOException ZipException
程序1:
//Java program to illustrate InflaterInputStream class
import java.io.*;
import java.util.Arrays;
import java.util.zip.DeflaterInputStream;
import java.util.zip.InflaterOutputStream;
class InflaterOutputStreamDemo
{
public static void main(String[] args) throws IOException
{
byte b[] = {1, 2, 3, 4, 5, 6};
ByteArrayInputStream bin = new ByteArrayInputStream(b);
DeflaterInputStream din = new DeflaterInputStream(bin);
byte c[] = new byte[10];
din.read(c);
din.close();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
InflaterOutputStream ios = new InflaterOutputStream(bos);
//illustrating write(byte b[],int off,int len)
ios.write(c);
//flushing
ios.flush();
//Finishes writing uncompressed data to the output stream
// without closing the underlying stream.
ios.finish();
System.out.println(Arrays.toString(bos.toByteArray()));
bos.close();
//illustrating close()
ios.close();
}
}
输出:
[1, 2, 3, 4, 5, 6]
程序2:
//Java program to illustrate InflaterInputStream class
import java.io.*;
import java.util.Arrays;
import java.util.zip.DeflaterInputStream;
import java.util.zip.InflaterOutputStream;
class InflaterOutputStreamDemo
{
public static void main(String[] args) throws IOException
{
byte b[] = {1, 2, 3, 4, 5, 6};
ByteArrayInputStream bin = new ByteArrayInputStream(b);
DeflaterInputStream din = new DeflaterInputStream(bin);
FileOutputStream fos=new FileOutputStream("file.txt");
byte c[] = new byte[10];
din.read(c);
fos.write(c);
din.close();
fos.close();
//reading the compressed data
FileInputStream fis = new FileInputStream("file.txt");
ByteArrayOutputStream bos1=new ByteArrayOutputStream();
InflaterOutputStream ios = new InflaterOutputStream(bos1);
int ch;
//illustrating write() method
while ( (ch=fis.read() ) != -1)
{
ios.write(ch);
}
System.out.print(Arrays.toString(bos1.toByteArray()));
}
}
输出:
[1, 2, 3, 4, 5, 6]
下一篇: Java 中的 Java.util.zip.InflaterInputStream 类
相关用法
- Java Java.util.zip.ZipOutputStream用法及代码示例
- Java Java.util.zip.ZipEntry用法及代码示例
- Java Java.util.zip.GZIPInputStream用法及代码示例
- Java Java.util.zip.DeflaterInputStream用法及代码示例
- 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.InflaterOutputStream class in Java。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。