0

I get the exception

java.util.zip.ZipException: invalid distances set
    at java.base/java.util.zip.InflaterInputStream.read(InflaterInputStream.java:165)
    at java.base/java.util.zip.ZipInputStream.read(ZipInputStream.java:195)
    at java.base/java.io.FilterInputStream.read(FilterInputStream.java:107)

when I want to unzip a file that I have copied before with

FileUtils.copyFile(File srcFile, File destFile)

(org.apache.commons.io).

If I don't copy the file and use the original zip file, the unzipping works just fine.

I have also used a different file-copy API from google guava. But the error is the same when I want to unzip the file.

The file I want to copy and unzip is a large file: its an adopt-open-jdk zip file.

I don't think it is an error in the unzipping logic. It is more related to what the copy does to the file such that it can't be unzipped correctly.

I use the following sample code for unzipping: https://github.com/eugenp/tutorials/blob/master/core-java-modules/core-java-io/src/main/java/com/baeldung/unzip/UnzipFile.java

Edit: the copied file does not become corrupt. The file size is identical with the original and I can open the copied zip with 7zip with no errors. Content is complete.

micmei
  • 49
  • 1
  • 6
  • See if your zip file has been corrupt or now. Try to open it with winzip/winrar first without using Java. See if it opens....IF not then it is corrupt on copy. I suggest you look into https://stackoverflow.com/questions/1946298/copy-and-validate-a-zip-file-via-java for different ways that might not corrupt the destination file. – JCompetence Aug 27 '21 at 10:31
  • I can open them with 7zip after copying. They are not corrupt. Also the file size is the same. – micmei Aug 27 '21 at 12:50
  • Could you try https://stackoverflow.com/questions/9324933/what-is-a-good-java-library-to-zip-unzip-files Lots of great examples /libs that you could use – JCompetence Aug 27 '21 at 12:57
  • I have already had a look into that post and even tried some of the other zip libs. Some of them were not working anymore, did not prevent zipslib or are so old and possibly not maintained that I would not want to rely on them in a professionell environment. Also, again, the original file can be unzipped with no problem. It is the copying which produces the problem. Not the unzipping obviously. – micmei Aug 27 '21 at 16:57

1 Answers1

0

I found the error myself. The previous maven build process copied the zip-file incorrectly and incompletely into a target jar file instead of inside the target folder directly. After that, I was accessing that file via classloader and the fileutils.copy copied an already incorrectly stored zip.

My bad, I did compare the wrong files when writing they were identical.

micmei
  • 49
  • 1
  • 6