Skip to content Skip to sidebar Skip to footer

Android: Decompress String That Was Compressed With Php Gzcompress()

How can i decompress a String that was zipped by PHP gzcompress() function? Any full examples? thx I tried it now like this: public static String unzipString(String zippedText) thr

Solution 1:

PHP's gzcompress uses Zlib NOT GZIP

publicstatic String unzipString(String zippedText) {
    Stringunzipped=null;
    try {
        byte[] zbytes = zippedText.getBytes("ISO-8859-1");
        // Add extra byte to array when Inflater is set to truebyte[] input = newbyte[zbytes.length + 1];
        System.arraycopy(zbytes, 0, input, 0, zbytes.length);
        input[zbytes.length] = 0;
        ByteArrayInputStreambin=newByteArrayInputStream(input);
        InflaterInputStreamin=newInflaterInputStream(bin);
        ByteArrayOutputStreambout=newByteArrayOutputStream(512);
        int b;
        while ((b = in.read()) != -1) {
            bout.write(b); }
        bout.close();
        unzipped = bout.toString();
    }
    catch (IOException io) { printIoError(io); }
    return unzipped;
 }
privatestaticvoidprintIoError(IOException io)
{
    System.out.println("IO Exception: " + io.getMessage());
}

Solution 2:

Try a GZIPInputStream. See this example and this SO question.

Solution 3:

See

http://developer.android.com/reference/java/util/zip/InflaterInputStream.html

since the DEFLATE algorithm is gzip.

Post a Comment for "Android: Decompress String That Was Compressed With Php Gzcompress()"