BZIP-OutputStream 的问题
首先是一些代码:
ByteArrayOutputStream bos = new ByteArrayOutputStream();
CBZip2OutputStream zos = new CBZip2OutputStream(bos);
provider.sendXMLFilelist(zos);
zos.flush();
bos.flush();
length = bos.size();
“provider”发送(比方说)200 个字节到“zos”。但是 length
是 == 1。我知道 bzip 很好,但是 1 个字节似乎少了一点。
当我这样做时: provider.sendXMLFilelist(bos);
长度为 == 200。
为什么 CBZip2OutputStream 不输出所有压缩字节?
我正在使用此实现: http://www.kohsuke.org/bzip2/
first some code:
ByteArrayOutputStream bos = new ByteArrayOutputStream();
CBZip2OutputStream zos = new CBZip2OutputStream(bos);
provider.sendXMLFilelist(zos);
zos.flush();
bos.flush();
length = bos.size();
"provider" send (lets say) 200 bytes to "zos". But length
is == 1. I know bzip is good, but 1 byte seems a litte less.
When I do: provider.sendXMLFilelist(bos);
than length is == 200.
Why doesn't CBZip2OutputStream output all of his compressed bytes?
I'm using this implementation: http://www.kohsuke.org/bzip2/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想我现在有了答案。您必须
.close()
bzip2 流。 Bzip2 是一个块编解码器,它不知道是否必须填充数据或是否还有更多数据。因此,通过告诉他关闭流,他可以输出所有压缩数据。
I think i now have the answer. you have to
.close()
the bzip2 stream. Bzip2 ist a block codec and it doesn't know if it has to pad the data or if there is more.So by telling him to close the stream brings him to output all of its compressed data.
我过去曾遇到过这个库实现的问题,我建议您查看 阿帕奇公共资源。迁移不应该很复杂(替换 CBZip2OutputStream -> BZip2CompressorOutputStream 就可以了)。
I've had issues with this library implementation in the past, I'd recommend you to look at another bzip2 implementation from Apache commons. Migration shouldn't be complex (replace CBZip2OutputStream -> BZip2CompressorOutputStream and you should go).