views:

588

answers:

3

I have written a sample program to compress and decompress data using GZIP in blackberry. This program works fine.

I have written a sample program to compress and decompress data using GZIP in Java. This program also works fine.

But if I compress the data using BlackBerry. I am unable to decompress the data in java.

How to overcome from this issue.

Thanks Deepak

+2  A: 

You should try a reference GZIP implementation like the gzip tool itself. Then you will get a better understanding which of your ends is not standard-compliant.

ypnos
A: 

When you say, "I have written a sample program," do you mean you wrote your own GZIP code, or you wrote a program that uses GZIPInputStream?

If you just want something that works, you should definitely use the core Java library.

If you are trying to satisfy your curiosity about how GZIP works and want to write your own code as a learning exercise, you'll have to provide much more detail.

erickson
hi, I am using GZIPInputStream ....
Sam97305421562
+2  A: 

If you follow the sample code given in the BlackBerry Javadocs for GZIPOutputStream, it should be compressing it correctly.

Sample code

public static byte[] compress( byte[] data )
{   
    try
    {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        GZIPOutputStream gzipStream = new GZIPOutputStream( baos, 6, GZIPOutputStream.MAX_LOG2_WINDOW_LENGTH );
        gzipStream.write( data );
        gzipStream.close();
    }
    catch(IOException ioe)
    {
        return null;
    }

    return baos.toByteArray();
}
Marc Novakowski