By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,986 Members | 1,944 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,986 IT Pros & Developers. It's quick & easy.

bzip using

P: n/a
I'm was planning on evaluating the use of bzip compression (instead of
the default java compression algorithms) for purposes of storage in a
database. So I grabbed the bzip libraries
(http://jakarta.apache.org/commons/sandbox/compress/) for this
purpose.

The exmpales on the Jakarta website are limited to a usage pattern for
reading/writing to/from a file. Is it appropriate to use this API for
storage to/from a byte array (for storage in a DB)?

Here's what I'm trying...

public static ZipObject bZip(Serializable inObj) throws IOException {

ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
ObjectOutputStream objOut = new ObjectOutputStream(byteOut);
objOut.writeObject(inObj);

byte[] dataArray = byteOut.toByteArray();
int origSize = dataArray.length;

ByteArrayOutputStream bZipByteOut = new ByteArrayOutputStream();
CBZip2OutputStream bZipOut = new CBZip2OutputStream(bZipByteOut);

bZipOut.write(dataArray, 0, dataArray.length);
byte[] compressedDataArray = bZipByteOut.toByteArray();

....but the output is eratic and can never be decmopressed (but am able
to save the byte array to a database).

Am I doing something foolishly wrong?
Jul 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.