Home » Category » Java Enterprise java bean & Java EE (EJB)

Java Enterprise java bean & Java EE (EJB): ZipEntry.getSize() always returns -1 when zipped with java.util.zip

300| Sun, 23 Sep 2007 14:49:00 GMT| makeschina| Comments (1)

Hi,

using java.util.zip works just fine when creating ZIP files. It only seems that the attribute "Size" is not set properly when using setSize(...).

When I zip the ZipEntry and set the size with setSize(long x), my debugger tells me that the ZipEntry-Object has in fact the desired size set.

But when I open the very same file later on and unzip the ZipEntries, they have a size of -1. When I open this file with WinZip, the correct sizes are shown. When I add files to the Zip file with WinZip, my Java code shows -1 for the files I added via java.util.zip, and correct sizes for the WinZip-added entries.

Any idea on that?

Lorenz

Keywords & Tags: zipentry.getsize, always, returns, -1, zipped, java.util.zip, java, enterprise, bean, ee, ejb

URL: http://java.itags.org/java-bean-j2ee/156777/
 
«« Prev - Next »» 1 helpful answers below.

I've been having the same issue with the file size, and noticed the following.

You can see the uncompressed file size on an entry accurately while reading in, if you call closeEntry() on your ZipInputStream. Strange in my opinion, since this is information you might want to know before you read the entry into a byte array, such that you can set up the byte array's capacity.

Perhaps this is not intended functionality?

mark_crossfielda | Tue, 10 Jul 2007 18:37:00 GMT |

Java Enterprise java bean & Java EE (EJB) Hot Answers

Java Enterprise java bean & Java EE (EJB) New questions

Java Enterprise java bean & Java EE (EJB) Related Categories