rizzletang
rizzletang

Reputation: 61

Is there a Java equivalent of php's gzdeflate?

I'm using Java to construct a url to a php site. The query string has a parameter that has been compressed using php's gzdeflate. Is there a way in Java that I can do the same thing gzdeflate does?

Upvotes: 1

Views: 1446

Answers (3)

0oneo
0oneo

Reputation: 695

public static void testInflate() throws IOException {
byte[] bytes = hexStringToByteArray("73cecf2d284a2d2e56c84d55482c4ec9c9ceca490400");

ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
InflaterInputStream iis = new InflaterInputStream(bis, new Inflater(true));

byte[] buffer = new byte[1024];
int len = -1;
String result = "";

while ((len = iis.read(buffer)) != -1) {
  result += new String(Arrays.copyOf(buffer, len), "utf-8");
}

System.out.println(result);

}

Upvotes: 0

Peter Lawrey
Peter Lawrey

Reputation: 533660

If you want to read a GZIP compressed stream you should use the GZIPInputStream.

The Inflator/Deflator is a stripped down compression stream which is slightly faster and more compact but isn't compatible with any other file type AFAIK.

Upvotes: 1

Jeremy
Jeremy

Reputation: 5435

I believe you are looking for the Deflater class:

http://download.oracle.com/javase/6/docs/api/java/util/zip/Deflater.html

For info about the differences: http://php.net/manual/en/function.gzinflate.php

Upvotes: 1

Related Questions