我一直在使用php通过创建一个套接字与我的Java应用程序进行通信,从Java端开始,我将压缩结果并将这些字节写入php。
public static byte[] compressString(byte[] b) throws IOException{
byte[] compressedBytes = null;
ByteArrayOutputStream out = new ByteArrayOutputStream(b.length);
try{
GZIPOutputStream gzip = new GZIPOutputStream(out);
gzip.write(b, 0, b.length);
gzip.finish();
gzip.flush();
gzip.close();
compressedBytes = out.toByteArray();
System.out.println("comp1::"+compressedBytes+", length::"+compressedBytes.length);
}finally{
out.close();
}
return compressedBytes;
}
但当我执行时
$data = fgets($fp);
$decompData = gzuncompress($data);
$decompData返回null。
请提供一个解决方案,因为我已经尝试了使用gzuncompress,gzdecode和所有可能的选项的Deflater。我这里一定少了什么东西。把我看作php的新手。
您需要对gzip流使用gzdecode()
,并且可能需要使用"rb"
打开文件以读取二进制数据而无需翻译。