PHP's gzuncompress function in Java?

我的未来我决定 提交于 2019-12-11 10:47:18

问题


I'm compressing a string using PHP's gzcompress() function:

http://us2.php.net/manual/en/function.gzcompress.php

I'd like to take the output from the PHP compression function and decompress the string in Java. Can anyone send me down the right path?

Thanks so much!


回答1:


have a look to GZIPInputStream:

GZIPInputStream gzipInputStream = new GZIPInputStream(new FileInputStream(inFilename));
byte[] buf = new byte[1024];
int len;
while ((len = gzipInputStream.read(buf)) > 0) {
    // buf contains uncompressed data      
}



回答2:


This is very old, but it might just contain the right info to get you started: http://java.sun.com/developer/technicalArticles/Programming/compression/




回答3:


Put the data into a ByteArrayInputStream, then you should be able to decode it with GZipInputStream.

To get the bytes out of the String, try getBytes("ISO-8859-1"). This encoding won't change the incoming bytes.



来源:https://stackoverflow.com/questions/1271246/phps-gzuncompress-function-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!