Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在GZIPInputStream中使用GZipStream(C)从zipped解压响应流_Java_Gzip - Fatal编程技术网

Java 在GZIPInputStream中使用GZipStream(C)从zipped解压响应流

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); 我也试过了

我正在尝试从.net中间件解压响应。已经使用GZipStream对响应进行了压缩

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能够解压缩响应。