Java 在GZIPInputStream中使用GZipStream(C)从zipped解压响应流
我正在尝试从.net中间件解压响应。已经使用GZipStream对响应进行了压缩Java 在GZIPInputStream中使用GZipStream(C)从zipped解压响应流,java,gzip,Java,Gzip,我正在尝试从.net中间件解压响应。已经使用GZipStream对响应进行了压缩 GZipStream zipStream = new GZipStream(fileStream, CompressionMode.Compress, true); 当我在java中使用GZIPInputStream解压文件时。我得到一个IOException,消息不是zip格式,代码如下 GZIPInputStream gzin = new GZIPInputStream(response); 我也试过了
GZipStream zipStream = new GZipStream(fileStream, CompressionMode.Compress, true);
当我在java中使用GZIPInputStream解压文件时。我得到一个IOException,消息不是zip格式,代码如下
GZIPInputStream gzin = new GZIPInputStream(response);
我也试过了
ByteArrayInputStream memstream = new ByteArrayInputStream(buffer2);
GZIPInputStream gzin = new GZIPInputStream(memstream);
欢迎任何帮助或建议。
提前谢谢试试这样的
GZIPInputStream gis = null;
FileOutputStream fos = null;
try {
gis = new GZIPInputStream(new FileInputStream("pathOfTheGZipFile"));
fos = new FileOutputStream("pathOfDecompressedFile");
byte[] buffer = new byte[gis.available()];
int len;
while((len = gis.read(buffer)) != -1){
fos.write(buffer, 0, len);
}
} catch (IOException e) {
e.printStackTrace();
}
finally {
fos.close();
gis.close();
}
我终于找到了解决方案,在服务器返回的响应中,前几个字节没有压缩,因此如果有人遇到相同的问题,您只需要检查字节。在我从响应中删除这些字节之后。它开始工作。我正在尝试解压缩一个已压缩的服务器响应。响应头不包含信息。但是它是压缩文件,我确信它是你在试图读取一些url并获取gzip中的数据吗?在InputStream中读取响应并向GZIPInputStream提供inputstreamObj我做了相同的操作,但我一次又一次地从GZIPInputStream中获取zip格式的文件,而c等效的GZipStream能够解压缩响应。