1

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

http://us2.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!

Audrius Meškauskas
  • 20,936
  • 12
  • 75
  • 93
Kirk Ouimet
  • 27,280
  • 43
  • 127
  • 177

3 Answers3

3

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      
}
dfa
  • 114,442
  • 31
  • 189
  • 228
0

This is very old, but it might just contain the right info to get you started: http://java.sun.com/developer/technicalArticles/Programming/compression/

Simon Groenewolt
  • 10,607
  • 1
  • 36
  • 64
0

Put the data into a ByteArrayInputStream, then you should be able to decode it with GZipInputStream.

To get the bytes out of the String, try getBytes("ISO-8859-1"). This encoding won't change the incoming bytes.

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820