Exception in thread "main" java.io.EOFException: Unexpected end of ZLIB input stream at java.util.zip.InflaterInputStream.fill(InflaterInputStream.java:240) at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:158) at java.util.zip.GZIPInputStream.read(GZIPInputStream.java:117) at java.io.FilterInputStream.read(FilterInputStream.java:107) at coderbean.ZipHelper.uncompress(ZipHelper.java:52) at coderbean.Main.main(Main.java:12)
/** * Writes remaining compressed data to the output stream and closes the * underlying stream. * @exception IOException if an I/O error has occurred */ publicvoidclose()throws IOException { if (!closed) { finish(); if (usesDefaultDeflater) def.end(); out.close(); closed = true; } }
/** * Finishes writing compressed data to the output stream without closing * the underlying stream. Use this method when applying multiple filters * in succession to the same output stream. * 在该方法中才会将压缩后的数据输出到输入流,由于原来的代码会调用 close()方法,从而 * 间接调用了 finish() 方法。 * @exception IOException if an I/O error has occurred */ publicvoidfinish()throws IOException { if (!def.finished()) { def.finish(); while (!def.finished()) { intlen= def.deflate(buf, 0, buf.length); if (def.finished() && len <= buf.length - TRAILER_SIZE) { // last deflater buffer. Fit trailer at the end writeTrailer(buf, len); len = len + TRAILER_SIZE; out.write(buf, 0, len); return; } if (len > 0) out.write(buf, 0, len); } // if we can't fit the trailer at the end of the last // deflater buffer, we write it separately byte[] trailer = newbyte[TRAILER_SIZE]; writeTrailer(trailer, 0); out.write(trailer); } }
/** * Closes the decompressor and discards any unprocessed input. * This method should be called when the decompressor is no longer * being used, but will also be called automatically by the finalize() * method. Once this method is called, the behavior of the Inflater * object is undefined. */ publicvoidend() { synchronized (zsRef) { longaddr= zsRef.address(); zsRef.clear(); if (addr != 0) { end(addr); buf = null; } } }
public classInflaterInputStreamextendsFilterInputStream { /** * Closes this input stream and releases any system resources associated * with the stream. * @exception IOException if an I/O error has occurred */ publicvoidclose()throws IOException { if (!closed) { if (usesDefaultInflater) inf.end(); in.close(); closed = true; } } }