本文共 1864 字,大约阅读时间需要 6 分钟。
解压 war/jar文件时出现以下错误:
java.util.zip.ZipException: invalid distance too far back at org.apache.commons.compress.archivers.zip.ZipArchiveInputStream.readFromInflater(ZipArchiveInputStream.java:478) at org.apache.commons.compress.archivers.zip.ZipArchiveInputStream.readDeflated(ZipArchiveInputStream.java:443) at org.apache.commons.compress.archivers.zip.ZipArchiveInputStream.read(ZipArchiveInputStream.java:384) at java.io.InputStream.read(Unknown Source) at org.apache.commons.compress.utils.IOUtils.copy(IOUtils.java:75) at org.apache.commons.compress.utils.IOUtils.copy(IOUtils.java:56) at com.xunge.AESFileEncoder$1.run(AESFileEncoder.java:149) at java.lang.Thread.run(Unknown Source) Caused by: java.util.zip.DataFormatException: invalid distance too far back at java.util.zip.Inflater.inflateBytes(Native Method) at java.util.zip.Inflater.inflate(Unknown Source) at org.apache.commons.compress.archivers.zip.ZipArchiveInputStream.readFromInflater(ZipArchiveInputStream.java:476) … 7 more相关代码:
PipedInputStream pin = new PipedInputStream(); PipedOutputStream pout = new PipedOutputStream(pin); new Thread(new Runnable() { public void run() { try { IOUtils.copy(ais, pout); pout.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }).start(); ArchiveInputStream inJar = new ArchiveStreamFactory() .createArchiveInputStream(ArchiveStreamFactory.JAR, pin);
以上代码是没有问题,如果使用 pin 的代码和 pin 的声明代码中间隔了太多的代码就会产生此异常。具体没有做试验,也可能是有逻辑判断语句的原因。
转载地址:http://qfcja.baihongyu.com/