public InputStream getInputStream(final ZipEntry ze) throws IOException, ZipException { if (!(ze instanceof Entry)) { return null; } final OffsetEntry offsetEntry = ((Entry) ze).getOffsetEntry(); ZipUtil.checkRequestedFeatures(ze); final long start = offsetEntry.dataOffset; final BoundedInputStream bis = new BoundedInputStream(start, ze.getCompressedSize()); switch (ze.getMethod()) { case 0: { return bis; } case 8: { bis.addDummy(); final Inflater inflater = new Inflater(true); return new InflaterInputStream(bis, inflater) { public void close() throws IOException { super.close(); inflater.end(); } }; } default: { throw new ZipException("Found unsupported compression method " + ze.getMethod()); } } }
/** * Writes bytes to ZIP entry. * * @param b the byte array to write * @param offset the start position to write from * @param length the number of bytes to write * @throws IOException on error */ @Override public void write(byte[] b, int offset, int length) throws IOException { if (entry == null) { throw new IllegalStateException("No current entry"); } ZipUtil.checkRequestedFeatures(entry.entry); entry.hasWritten = true; if (entry.entry.getMethod() == DEFLATED) { writeDeflated(b, offset, length); } else { writeOut(b, offset, length); written += length; } crc.update(b, offset, length); count(length); }