0

首先是一些代码:

ByteArrayOutputStream bos = new ByteArrayOutputStream();
CBZip2OutputStream zos = new CBZip2OutputStream(bos);

provider.sendXMLFilelist(zos);
zos.flush();
bos.flush();

length = bos.size();

“提供者”向“zos”发送(假设)200 个字节。但是length是 == 1。我知道 bzip 很好,但是 1 字节似乎少了一点。

当我这样做时:provider.sendXMLFilelist(bos);比长度== 200。

为什么 CBZip2OutputStream 不输出他所有的压缩字节?

我正在使用这个实现:http ://www.kohsuke.org/bzip2/

4

2 回答 2

2

我想我现在有了答案。您必须.close()使用 bzip2 流。Bzip2 是一个块编解码器,它不知道是否必须填充数据或是否还有更多。

因此,通过告诉他关闭流,他可以输出所有压缩数据。

于 2010-12-06T16:29:26.437 回答
0

我过去曾遇到过这个库实现的问题,我建议您查看Apache commons的另一个 bzip2 实现。迁移不应该很复杂(替换 CBZip2OutputStream -> BZip2CompressorOutputStream ,你应该去)。

于 2010-12-05T17:10:36.013 回答