Android:解压缩使用 PHP gzcompress() 压缩的字符串
如何解压缩由 PHP gzcompress() 函数压缩的字符串?
有完整的例子吗?
谢谢,
我现在尝试了这样的操作:
public static String unzipString(String zippedText) throws Exception
{
ByteArrayInputStream bais = new ByteArrayInputStream(zippedText.getBytes("UTF-8"));
GZIPInputStream gzis = new GZIPInputStream(bais);
InputStreamReader reader = new InputStreamReader(gzis);
BufferedReader in = new BufferedReader(reader);
String unzipped = "";
while ((unzipped = in.readLine()) != null)
unzipped+=unzipped;
return unzipped;
}
但是如果我尝试解压缩 PHP gzcompress (-ed) 字符串,它就不起作用。
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) throws Exception
{
ByteArrayInputStream bais = new ByteArrayInputStream(zippedText.getBytes("UTF-8"));
GZIPInputStream gzis = new GZIPInputStream(bais);
InputStreamReader reader = new InputStreamReader(gzis);
BufferedReader in = new BufferedReader(reader);
String unzipped = "";
while ((unzipped = in.readLine()) != null)
unzipped+=unzipped;
return unzipped;
}
but it's not working if i i'm trying to unzip a PHP gzcompress (-ed) string.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
PHP 的 gzcompress 使用 Zlib 而不是 GZIP
PHP's gzcompress uses Zlib NOT GZIP
尝试 GZIPInputStream。请参阅此示例和这个问题。
Try a GZIPInputStream. See this example and this SO question.
请参阅
http://developer.android.com/reference/java/util/ zip/InflaterInputStream.html
因为 DEFLATE 算法是 gzip。
See
http://developer.android.com/reference/java/util/zip/InflaterInputStream.html
since the DEFLATE algorithm is gzip.