This page contains an archived post to the Java Answers Forum made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
Posted by Tim Ragsdale on November 10, 2000 at 1:57 PM
Does anybody have an answer to this?
> > I'm using sockets to transfer zip files (I use WinZip 8.0) to/from remote machine (remote and local are same in this case).
> > I use a zipInputStream to read in a ZipEntry object from a zip file, but when I write that same object to a zipOutputStream, I get a
> > java.util.zip.ZipException: invalid entry compressed size
> > For some reason, it's unable to write the correct compressed size to the zipOutputStream.
> > So, instead I create a new ZipEntry object with the same name and size, and put it on the zipOutputStream. But when the client reads from the socket's input stream, in our case, the zipInputStream, it cannot get the size of the zipEntry (zipEntry.getSize() = -1). Same thing happens when I read from a URL connection. This is a problem b/c if I read more or less class bytes, the target class will not be resolved by my custom class loader.
> > Why can't the zip entry size be determined when it's being read over a socket or URL connection - how can the size value be preserved ?
> > platform: windows NT 4.o
> > jdk1.2.2-006
> > thanks in advance,
> > john
> Since the size of the zipEntry doesn't seem to be available right off hand, I can use zipOutputStream.available() to check for the end of the current zipEntry as I'm reading from the input stream X number of bytes. Then, if again I ask the current zip entry for its size (though at this point I already now the size based on the number of actual bytes read) it comes back with the proper value.
> I'm open to any other suggestions.