生化危机5 inflate:微信 invalid codee lengths set : -3

jboss7.x - java: Zip Exception invalid codes length? - Stack Overflow
Join the Stack Overflow Community
Stack Overflow is a community of 7.1 million programmers, just like you, helping each other.
J it only takes a minute:
When I'm writing entries into a zip file like this:
ZipEntry ze = zin.getNextEntry();
while (ze != null) {
InputStream is = zf.getInputStream(ze);
zos.putNextEntry(ze);
while ((len = is.read(buffer)) &= 0) {
zos.write(buffer, 0, len);
zos.closeEntry();
ze = zin.getNextEntry();
I get the following exception on the second while loop:
java.util.zip.ZipException: invalid code lengths set
at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:164)
at java.io.FilterInputStream.read(FilterInputStream.java:107)
Anybody knows why this exception is thrown and what does it mean?
P.S. I should mention that I'm running this on a listeners on JBoss 7.1.1 in order to zip vaious log files from different folders. There's a thread for each folder. Could the fact of using multiple threads lead to this problem?
You are setting the ZipEntry of the new zip file to the same instance you got from the original file. This implies that all values must match, but this fails if the compressed size of the written entry does not match the compressed size of the source file. And the tiniest bit of difference between the original compression code and the one you are using now will yield to different compressed sizes. To make it run you have to create a copy of the ZipEntry for the output and reset the compressed size on it.
By the way, you are using zin.getNextEntry() and zf.getInputStream(ze) in your code which implies that you are using a ZipFile and a ZipInputStream at the same time. If they refer to the same file, it’s a waste of resources, if they refer to different files, you can expect even more problems.
Decide for either ZipFile
ZipFile zf = …
ZipOutputStream zos = …
byte[] buffer = …
for(Enumeration&? extends ZipEntry& e=zf.entries(); e.hasMoreElements();) {
ZipEntry ze = e.nextElement();
InputStream is = zf.getInputStream(ze);
ZipEntry zeOut=new ZipEntry(ze);
zeOut.setCompressedSize(-1);
zos.putNextEntry(zeOut);
while ((len = is.read(buffer)) &= 0) {
zos.write(buffer, 0, len);
zos.closeEntry();
zos.close();
zf.close();
or ZipInputStream
ZipInputStream zin…
ZipOutputStream zos=…
byte[] buffer = …
ZipEntry ze = zin.getNextEntry();
while (ze != null) {
ZipEntry zeOut=new ZipEntry(ze);
zeOut.setCompressedSize(-1);
zos.putNextEntry(zeOut);
while ((len = zin.read(buffer)) &= 0) {
zos.write(buffer, 0, len);
zos.closeEntry();
ze = zin.getNextEntry();
zos.close();
zin.close();
95.2k11117203
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
rev .25812
Stack Overflow works best with JavaScript enabled|  
|  
|  
|  
|  
只需一步,快速开始
& & & & 《生化危机5:黄金版》
专题站||||||||||||
- [阅读权限 10]
- [回帖奖励
- [回帖奖励
- [阅读权限 10]
- [阅读权限 10]
- [阅读权限 25]
- [阅读权限 25]
Powered by}

我要回帖

更多关于 invalid code page 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信