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?