Tag Archives: ZipOutputStream

zipOutputStream.closeEntry() : invalid entry compressed size

have you hit an exception like this:

java.util.zip.ZipException: invalid entry compressed size (expected 960092 but got 962733 bytes)

?

Well, this is because ZipOutputStream tries to close a ZipEntry with a different size than its size property. This is because:

zipOutputStream.putNextEntry(inEntry);

OR

zipOutputStream.putNextEntry(new ZipEntry(inEntry));

Creating new ZipEntry like this resulting in copying all the properties of the old one. However the resulting zipped size can differ so if you don’t care about preserving other fields than name this constructor can be used:

zipOutputStream.putNextEntry(new ZipEntry(inEntry.getName()));