Search code examples
javaphpstringgzipgzipinputstream

PHP's gzuncompress function in Java?


I'm compressing a string using PHP's gzcompress() function:

https://www.php.net/manual/en/function.gzcompress.php

I'd like to take the output from the PHP compression function and decompress the string in Java. Can anyone send me down the right path?

Thanks so much!


Solution

  • have a look to GZIPInputStream:

    GZIPInputStream gzipInputStream = new GZIPInputStream(new FileInputStream(inFilename));
    byte[] buf = new byte[1024];
    int len;
    while ((len = gzipInputStream.read(buf)) > 0) {
        // buf contains uncompressed data      
    }