java.util.zip.ZipException: invalid block type under JDK1.4.2
I hat a long fight until I got that one:
// java.util.zip.ZipException: invalid block type
// at
// java.util.zip.InflaterInputStream.read(InflaterInputStream.java:140)
// at
// java.util.zip.GZIPInputStream.read(GZIPInputStream.java:87)
// at
// java.util.zip.InflaterInputStream.read(InflaterInputStream.java:105)
...
The reason was that the GZIPInputStream constructor consumes about 10 bytes.
If you do a reset before the first read, under 1.4.2 those 10 bytes will be read again - under jdk1.5.0, it is fortunately no longer possible to do such a reset.
So, that's my fix:
InputStream in = new GZIPInputStream(isFromDb)
...
//the next method applies not just for GZIPInputStream but any InputStream
boolean markSupported = in.markSupported();
if (markSupported) {
if (in instanceof GZIPInputStream) {
String vmVersion = System.getProperty("java.vm.version");
if (!vmVersion.startsWith("1.5")) {
markSupported = false;
log.debug("don't believe markSupported() if it is jdk1.4.2"; }
}
}
if (markSupported) {
in.reset()
}
I would be interested to hear if other people run into the same issue and whether they solved it differently!
https://www.privasphere.com/e.do?email=hauser@acm.org