Bomb Diggy:
Is it possible to use java.util.zip to read and decompress/inflate a
self-extracting zip file? I've been able to unzip regular zip files
(produced by WinZip), but not self-extracting zip files (produced by
Winzip and PKZip).
A zip file looks like this (simplified):
HEADER1 FILE1 HEADER2 FILE2 [... other pairs] HEADER1 HEADER2 [...all
headers]
So the headers are repeated at the end of the archive.
A self-extracting zip file looks like almost like this, only a CODE
prefix is different:
CODE HEADER1 FILE1 [...rest as above]
where CODE is some executable code with unzip functionality that
searches the file it is in for headers and then unzips the data.
The problem with java.util.zip is that it never reads the header
directory at the end, which would be much quicker than going over the
complete file. It always expects a stream to start with a header.
So your only chance is to write code that searches for the first
header in an InputStream (skipping any potential CODE section), then
wrap a ZipInputStream around that. Then you can work with that
self-extracting zip file.
Here are pointers to the zip file format specs and related
information:
<
http://www.geocities.com/SiliconValley/Lakes/6686/zip-archive-file-format.html>.
IIRC a header starts with P K \003 \004 (or similar numbers, it's in
the specs). That's what you must search for.
Regards,
Marco