简体   繁体   English

java.util.zip.ZipException:无效的存储块长度

[英]java.util.zip.ZipException: invalid stored block lengths

I am trying to read a ZipArchiveEntry to String.我正在尝试将 ZipArchiveEntry 读取为字符串。 I have the below code and i run into exception我有以下代码,但遇到异常

My code is as below我的代码如下

StringWriter writer = new StringWriter();
IOUtils.copy(zipFile.getInputStream(zipArchiveEntry),
              writer,
              org.apache.commons.io.Charsets.UTF_8);

And I get the following exception我得到以下异常

java.util.zip.ZipException: invalid stored block lengths
at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:147)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158)
at java.io.InputStreamReader.read(InputStreamReader.java:167)
at java.io.Reader.read(Reader.java:123)
at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:2001)
at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1980)
at org.apache.commons.io.IOUtils.copy(IOUtils.java:1957)
at org.apache.commons.io.IOUtils.copy(IOUtils.java:1907)

Really stuck at it for a long time.真的坚持了很久。 Please help out.请帮忙。

I had a similar case of an apparently valid ZIP but had difficulties reading it using Java.我有一个明显有效的 ZIP 的类似案例,但在使用 Java 阅读时遇到了困难。 The exception was similar to yours but with a different stacktrace:该异常与您的类似,但具有不同的堆栈跟踪:

Caused by: java.util.zip.ZipException: invalid stored block lengths
at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:164)
at java.util.zip.ZipInputStream.read(ZipInputStream.java:194)
at java.util.zip.ZipInputStream.closeEntry(ZipInputStream.java:140)
at java.util.zip.ZipInputStream.getNextEntry(ZipInputStream.java:118)
...

In my case, the "malfunctioning" ZIP was created using an Ansible "archive" module on a CentOS machine:就我而言,“故障”ZIP 是使用 CentOS 机器上的 Ansible“归档”模块创建的:

- name: Create a zip archive
  archive:
    path: /tmp/mydir/
    dest: /tmp/mydir.zip
    format: zip

The fix was to add an asterisk at the end of the "path" when creating the ZIP:修复方法是在创建 ZIP 时在“路径”的末尾添加一个星号:

- name: Create a zip archive
  archive:
    path: /tmp/mydir/*
    dest: /tmp/mydir.zip
    format: zip

The content of the two ZIPs is the same but there is some difference in file/directory attributes within the ZIP that apparently cause the issue in Java.两个 ZIP 的内容相同,但 ZIP 中的文件/目录属性存在一些差异,这显然导致了 Java 中的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 原因:java.util.zip.ZipException:设置的代码长度无效 - Caused by: java.util.zip.ZipException: invalid code lengths set java.util.zip.ZipException:使用 SentenceModel 设置的代码长度无效 - java.util.zip.ZipException: invalid code lengths set with SentenceModel java.util.zip.ZipException:超额订阅的动态位长度树 - java.util.zip.ZipException: oversubscribed dynamic bit lengths tree mxmlc java.util.zip.ZipException:无效的块类型Actionscript-3 Papervision3D Flash开发 - mxmlc java.util.zip.ZipException: invalid block type Actionscript-3 Papervision3D Flash Develop java.util.zip.ZipException: 无效代码 -- 缺少块结束 --> 在调用 ZipInputStream.closeEntry() 时 - java.util.zip.ZipException: invalid code -- missing end-of-block --> while calling ZipInputStream.closeEntry() java.util.zip.ZipException:无效的通用标志:9 - java.util.zip.ZipException: invalid general purpose flag: 9 java.util.zip.ZipException:CEN标头无效(签名错误) - java.util.zip.ZipException: invalid CEN header (bad signature) java.util.zip.ZipException:无效的压缩方法 - java.util.zip.ZipException: invalid compression method java.util.zip.ZIPException: 不是 GZIP 格式 - java.util.zip.ZIPException: Not in GZIP format 修复 java.util.zip.ZipException - fixing java.util.zip.ZipException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM