Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ZipEntry unknown size although set

Tags:

java

zip

size

I searched and read all questions about ZipEntry (JAVA 7) but my problem is nowhere addressed:

I successfully zip and unzip files in JAVA, but although, at zip time, I set the uncompressed size by ZipEntry.setSize(long) to values surely smaller than int value, reading back, at unzip time, by ZipEntry.getSize() always returns -1. Although my programs run well, the verification part warns for unknown size.

How do I set the uncompressed size?


1 Answers

At first sight it looks like a bug, but as explained here it's actually not!

The size information (along with some other info like CRC) is stored compressed so to get access to this information you have to:

  1. First call getNextEntry() to get the first entry
  2. Right now calling getSize() will return -1
  3. Read the data of the file by calling read(buffer)
  4. Call getNextEntry() again
  5. At this point calling getSize() on the first entry will now return the correct size!

Weird, but that's how it apparently is supposed to work

like image 178
Pierre Ingmansson Avatar answered Oct 14 '25 10:10

Pierre Ingmansson