javastreambufferbzip

Problems with BZIP-OutputStream


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/


Solution

  • 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.