I have a problem. The current code works fine when I run it through IntelliJ,
but it fails with an exception when I run it in maven 3.
public static boolean isZipContent(InputStream inputstream) throws IOException {
BufferedInputStream bis = new BufferedInputStream(inputstream);
ZipInputStream zis = new ZipInputStream(bis);
ZipEntry ze = zis.getNextEntry();
if (ze == null) {
return false;
}
zis.closeEntry();
zis.close();
bis.close();
return true;
}
Exception:
java.util.zip.ZipException: invalid literal/lengths set
at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:164) ~[na:1.7.0_06]
at java.util.zip.ZipInputStream.read(ZipInputStream.java:193) ~[na:1.7.0_06]
at java.util.zip.ZipInputStream.closeEntry(ZipInputStream.java:139) ~[na:1.7.0_06]
The Zip files look just fine when I open them manually using WinZip or whatever – and as I said, everything works perfectly in IntelliJ.
I have debugged and checked file encoding, class loaders and everything, everything looks equal, but still the code fails consistently if I run the test using Maven3, but works in IntelliJ.
It fails on the zis.closeEntry(); with an exception.
I have made sure the stream is still open during debugging.
I’m using Java 1.6, on Win7. Maven 3.0.4. I’ve tried other versions of Java with the same result.
Does anyone have an idea of what is going on?
The problem was a corrupt Zip file…
What threw me off was that the table of contents with all the entries looked just fine, thus I thought the Zip file was fine.
Once I tried to actually unzip one of the files it failed.