问题描述
|
我正在使用Java来构建PHP网站的网址。查询字符串的参数已使用PHP \的gzdeflate压缩。在Java中,有什么方法可以执行gzdeflate的相同操作?
解决方法
我相信您正在寻找Deflater课程:
http://download.oracle.com/javase/6/docs/api/java/util/zip/Deflater.html
有关差异的信息:
http://php.net/manual/zh/function.gzinflate.php
, 如果要读取GZIP压缩流,则应使用GZIPInputStream。
Inflator / Deflator是一种简化的压缩流,速度稍快,更紧凑,但与其他任何文件类型AFAIK不兼容。
,
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);
}