Rebasing the Inflater support on jzlib which, unlike GNU ClassPath, has correct implementation of Huffman code. Making the implementation more easily testable by turning Inflater and ZipInputStream into pure delegates. Current implementation is going to need proper long support.
2 * Copyright (c) 1996, 2009, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
26 package java.util.zip;
28 import java.io.InputStream;
29 import java.io.IOException;
32 * This class implements an input stream filter for reading files in the
33 * ZIP file format. Includes support for both compressed and uncompressed
36 * @author David Connelly
39 class ZipInputStream extends InflaterInputStream implements ZipConstants {
40 private final org.apidesign.bck2brwsr.emul.zip.ZipInputStream impl;
43 * Creates a new ZIP input stream.
45 * <p>The UTF-8 {@link java.nio.charset.Charset charset} is used to
46 * decode the entry names.
48 * @param in the actual input stream
50 public ZipInputStream(InputStream in) {
52 impl = new org.apidesign.bck2brwsr.emul.zip.ZipInputStream(in);
56 * Creates a new ZIP input stream.
58 * @param in the actual input stream
61 * The {@linkplain java.nio.charset.Charset charset} to be
62 * used to decode the ZIP entry name (ignored if the
63 * <a href="package-summary.html#lang_encoding"> language
64 * encoding bit</a> of the ZIP entry's general purpose bit
69 public ZipInputStream(InputStream in, Charset charset) {
70 super(new PushbackInputStream(in, 512), new Inflater(true), 512);
71 usesDefaultInflater = true;
73 throw new NullPointerException("in is null");
76 throw new NullPointerException("charset is null");
77 this.zc = ZipCoder.get(charset);
82 * Reads the next ZIP file entry and positions the stream at the
83 * beginning of the entry data.
84 * @return the next ZIP file entry, or null if there are no more entries
85 * @exception ZipException if a ZIP file error has occurred
86 * @exception IOException if an I/O error has occurred
88 public ZipEntry getNextEntry() throws IOException {
89 return impl.getNextEntry();
93 * Closes the current ZIP entry and positions the stream for reading the
95 * @exception ZipException if a ZIP file error has occurred
96 * @exception IOException if an I/O error has occurred
98 public void closeEntry() throws IOException {
103 * Returns 0 after EOF has reached for the current entry data,
104 * otherwise always return 1.
106 * Programs should not count on this method to return the actual number
107 * of bytes that could be read without blocking.
109 * @return 1 before EOF and 0 after EOF has reached for current entry.
110 * @exception IOException if an I/O error occurs.
113 public int available() throws IOException {
114 return impl.available();
118 * Reads from the current ZIP entry into an array of bytes.
119 * If <code>len</code> is not zero, the method
120 * blocks until some input is available; otherwise, no
121 * bytes are read and <code>0</code> is returned.
122 * @param b the buffer into which the data is read
123 * @param off the start offset in the destination array <code>b</code>
124 * @param len the maximum number of bytes read
125 * @return the actual number of bytes read, or -1 if the end of the
127 * @exception NullPointerException if <code>b</code> is <code>null</code>.
128 * @exception IndexOutOfBoundsException if <code>off</code> is negative,
129 * <code>len</code> is negative, or <code>len</code> is greater than
130 * <code>b.length - off</code>
131 * @exception ZipException if a ZIP file error has occurred
132 * @exception IOException if an I/O error has occurred
134 public int read(byte[] b, int off, int len) throws IOException {
135 return impl.read(b, off, len);
139 * Skips specified number of bytes in the current ZIP entry.
140 * @param n the number of bytes to skip
141 * @return the actual number of bytes skipped
142 * @exception ZipException if a ZIP file error has occurred
143 * @exception IOException if an I/O error has occurred
144 * @exception IllegalArgumentException if n < 0
146 public long skip(long n) throws IOException {
151 * Closes this input stream and releases any system resources associated
153 * @exception IOException if an I/O error has occurred
155 public void close() throws IOException {
160 * Creates a new <code>ZipEntry</code> object for the specified
163 * @param name the ZIP file entry name
164 * @return the ZipEntry just created
166 protected ZipEntry createZipEntry(String name) {
167 return new ZipEntry(name);
171 public int read() throws IOException {
176 public boolean markSupported() {
177 return impl.markSupported();
181 public void mark(int readlimit) {
182 impl.mark(readlimit);
186 public void reset() throws IOException {
191 public int read(byte[] b) throws IOException {