java - Android: decompress string that was compressed with PHP gzcompress() -
how can decompress string zipped php gzcompress() function?
any full examples?
thx
i tried 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'm trying unzip php gzcompress (-ed) string.
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 byte array when inflater set 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()); }
Comments
Post a Comment