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).
16 *
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.
20 *
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
23 * questions.
24 */
25
26 package java.util.zip;
27
28 import java.io.InputStream;
29 import java.io.IOException;
30 import java.io.EOFException;
31 import java.io.PushbackInputStream;
32 import java.nio.charset.Charset;
33 import java.nio.charset.StandardCharset;
34 import static java.util.zip.ZipConstants64.*;
35
36 /**
37 * This class implements an input stream filter for reading files in the
38 * ZIP file format. Includes support for both compressed and uncompressed
39 * entries.
40 *
41 * @author David Connelly
42 */
43 public
44 class ZipInputStream extends InflaterInputStream implements ZipConstants {
45 private ZipEntry entry;
46 private int flag;
47 private CRC32 crc = new CRC32();
48 private long remaining;
49 private byte[] tmpbuf = new byte[512];
50
51 private static final int STORED = ZipEntry.STORED;
52 private static final int DEFLATED = ZipEntry.DEFLATED;
53
59 private ZipCoder zc;
60
61 /**
62 * Check to make sure that this stream has not been closed
63 */
64 private void ensureOpen() throws IOException {
65 if (closed) {
66 throw new IOException("Stream closed");
67 }
68 }
69
70 /**
71 * Creates a new ZIP input stream.
72 *
73 * <p>The UTF-8 {@link java.nio.charset.Charset charset} is used to
74 * decode the entry names.
75 *
76 * @param in the actual input stream
77 */
78 public ZipInputStream(InputStream in) {
79 this(in, StandardCharset.UTF_8);
80 }
81
82 /**
83 * Creates a new ZIP input stream.
84 *
85 * @param in the actual input stream
86 *
87 * @param charset
88 * The {@linkplain java.nio.charset.Charset charset} to be
89 * used to decode the ZIP entry name (ignored if the
90 * <a href="package-summary.html#lang_encoding"> language
91 * encoding bit</a> of the ZIP entry's general purpose bit
92 * flag is set).
93 *
94 * @since 1.7
95 */
96 public ZipInputStream(InputStream in, Charset charset) {
97 super(new PushbackInputStream(in, 512), new Inflater(true), 512);
98 usesDefaultInflater = true;
99 if(in == null) {
|
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).
16 *
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.
20 *
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
23 * questions.
24 */
25
26 package java.util.zip;
27
28 import java.io.InputStream;
29 import java.io.IOException;
30 import java.io.EOFException;
31 import java.io.PushbackInputStream;
32 import java.nio.charset.Charset;
33 import java.nio.charset.StandardCharsets;
34 import static java.util.zip.ZipConstants64.*;
35
36 /**
37 * This class implements an input stream filter for reading files in the
38 * ZIP file format. Includes support for both compressed and uncompressed
39 * entries.
40 *
41 * @author David Connelly
42 */
43 public
44 class ZipInputStream extends InflaterInputStream implements ZipConstants {
45 private ZipEntry entry;
46 private int flag;
47 private CRC32 crc = new CRC32();
48 private long remaining;
49 private byte[] tmpbuf = new byte[512];
50
51 private static final int STORED = ZipEntry.STORED;
52 private static final int DEFLATED = ZipEntry.DEFLATED;
53
59 private ZipCoder zc;
60
61 /**
62 * Check to make sure that this stream has not been closed
63 */
64 private void ensureOpen() throws IOException {
65 if (closed) {
66 throw new IOException("Stream closed");
67 }
68 }
69
70 /**
71 * Creates a new ZIP input stream.
72 *
73 * <p>The UTF-8 {@link java.nio.charset.Charset charset} is used to
74 * decode the entry names.
75 *
76 * @param in the actual input stream
77 */
78 public ZipInputStream(InputStream in) {
79 this(in, StandardCharsets.UTF_8);
80 }
81
82 /**
83 * Creates a new ZIP input stream.
84 *
85 * @param in the actual input stream
86 *
87 * @param charset
88 * The {@linkplain java.nio.charset.Charset charset} to be
89 * used to decode the ZIP entry name (ignored if the
90 * <a href="package-summary.html#lang_encoding"> language
91 * encoding bit</a> of the ZIP entry's general purpose bit
92 * flag is set).
93 *
94 * @since 1.7
95 */
96 public ZipInputStream(InputStream in, Charset charset) {
97 super(new PushbackInputStream(in, 512), new Inflater(true), 512);
98 usesDefaultInflater = true;
99 if(in == null) {
|