栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

DeflatorInputStream和DeflatorOutputStream不重建原始数据

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

DeflatorInputStream和DeflatorOutputStream不重建原始数据

责备历史先例。在Unix上,用于反转a的函数

deflate
称为
inflate
。因此,与许多其他Java
IO类不同,输入和输出流对不具有(显然)匹配的名称。

实际上,DeflaterOutputStream不允许您逆转通缩,而是在将字节从接收器传递到源时,对字节进行放气。DeflaterInputStream
也可以 放气,但是它在数据从源流向接收器时执行其操作。

为了读取未压缩(膨胀)格式的数据,您需要使用

InflaterInputStream

InflaterInputStream inputStream = new InflaterInputStream(arrayInputStream);

另外,由于可能无法在一个

read
调用中从流中获取所有压缩数据,因此需要使用循环。像这样:

int read;byte[] finalBuf = new byte[0], swapBuf;byte[] readBuffer = new byte[5012];ByteArrayInputStream arrayInputStream = new ByteArrayInputStream(        compressed);InflaterInputStream inputStream = new InflaterInputStream(        arrayInputStream);while ((read = inputStream.read(readBuffer)) != -1) {    System.out.println("Intermediate read: " + read);    swapBuf = finalBuf;    finalBuf = new byte[swapBuf.length + read];    System.arraycopy(swapBuf, 0, finalBuf, 0, swapBuf.length);    System.arraycopy(readBuffer, 0, finalBuf, swapBuf.length, read);}

最后,请确保在检索压缩字节之前先刷新deflater输出流(或者关闭流)。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/454560.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号