安卓:DECOM preSS字符串,它是COM pressed用PHP gzcom preSS() [英] Android: decompress string that was compressed with PHP gzcompress()
本文介绍了安卓:DECOM preSS字符串,它是COM pressed用PHP gzcom preSS()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何DECOM preSS被压缩由PHP gzcom preSS()函数的字符串?
How can i decompress a String that was zipped by PHP gzcompress() function?
任何完整的例子吗?
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;
}
,但它不工作,如果我我试图解压缩一个PHP gzcom preSS(-ed)字符串。
but it's not working if i i'm trying to unzip a PHP gzcompress (-ed) string.
推荐答案
PHP的gzcom preSS使用zlib的不是gzip
PHP's gzcompress uses Zlib NOT GZIP
public static String unzipString(String zippedText) {
String unzipped = null;
try {
byte[] zbytes = zippedText.getBytes("ISO-8859-1");
// Add extra byte to array when Inflater is set to true
byte[] input = new byte[zbytes.length + 1];
System.arraycopy(zbytes, 0, input, 0, zbytes.length);
input[zbytes.length] = 0;
ByteArrayInputStream bin = new ByteArrayInputStream(input);
InflaterInputStream in = new InflaterInputStream(bin);
ByteArrayOutputStream bout = new ByteArrayOutputStream(512);
int b;
while ((b = in.read()) != -1) {
bout.write(b); }
bout.close();
unzipped = bout.toString();
}
catch (IOException io) { printIoError(io); }
return unzipped;
}
private static void printIoError(IOException io)
{
System.out.println("IO Exception: " + io.getMessage());
}
这篇关于安卓:DECOM preSS字符串,它是COM pressed用PHP gzcom preSS()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文