bzip using

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • david

    bzip using

    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(Serializab le inObj) throws IOException {

    ByteArrayOutput Stream byteOut = new ByteArrayOutput Stream();
    ObjectOutputStr eam objOut = new ObjectOutputStr eam(byteOut);
    objOut.writeObj ect(inObj);

    byte[] dataArray = byteOut.toByteA rray();
    int origSize = dataArray.lengt h;

    ByteArrayOutput Stream bZipByteOut = new ByteArrayOutput Stream();
    CBZip2OutputStr eam bZipOut = new CBZip2OutputStr eam(bZipByteOut );

    bZipOut.write(d ataArray, 0, dataArray.lengt h);
    byte[] compressedDataA rray = bZipByteOut.toB yteArray();

    ....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?
Working...