|
From: Jim M. <jim...@co...> - 2006-03-01 21:27:53
|
I am trying to create a new zip file containing selected entries from
another zip file. I am using jazzlib-0.07 with Sun's JDK 1.5.0_04 on Redhat
Fedora Core 4 Linux.
I create an entry in the new file with the same name as the one in the old
file, then call the following method.
----------------------------
private void copyEntryData(ZipFile inputZipFile,
ZipOutputStream zipOutputStream, ZipEntry entry) {
try {
int data = 0;
InputStream inputStream = inputZipFile.getInputStream(entry);
while ((data = inputStream.read()) >= 0) {
zipOutputStream.write(data);
}
zipOutputStream.flush();
zipOutputStream.closeEntry();
inputStream.close();
} catch (IOException e) {
final String message = "Unable to read or write file";
recordException(message, e);
}
}
----------------------------
This runs without throwing an exception. Later, though, when I call
zipOutputStream.close(), I get:
----------------------------
Error when trying to close zip output stream:
/home/jmcmaster/nile/assets/dex/EXT065_TEXT/eps.zip
net.sf.jazzlib.ZipException: compressed size was 195651, but I expected
464058
at
net.sf.jazzlib.ZipOutputStream.closeEntry(ZipOutputStream.java:276)
at
net.sf.jazzlib.ZipOutputStream.finish(ZipOutputStream.java:336)
at
net.sf.jazzlib.DeflaterOutputStream.close(DeflaterOutputStream.java:171)
----------------------------
(NOTE: The actual expected size is 196653. The 464058 is the uncompressed
size. Jazzlib has a bug that sticks the wrong size in the exception
message.)
Trying to unzip the file yields:
----------------------------
Archive: eps.zip
End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory and zipfile comment will be found on
the last disk(s) of this archive.
unzip: cannot find zipfile directory in one of eps.zip or
eps.zip.zip, and cannot find eps.zip.ZIP, period.
----------------------------
I am processing two kinds of entries: xml files a few hundred bytes in
length, and EPS files several hundred thousand bytes in length. This never
happens with the former, but consistently happens with the latter. I do get
the same results with java's zip classes. A co-worker who experienced the
same problem worked around it by extracting the entry to a temporary disk
file, then writing from there to the output zip file. I would rather not if
I can avoid that. I read a java forum posting where someone solved a
similar problem by switching to TrueZip, but I would rather not do that
either.
Is there a way to fix this? I suspect something wrong in the deflater, but
have no clue how to debug it.
Thank you.
--
Jim McMaster
mailto:jim...@co...
|