1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/rt/emul/mini/src/main/java/java/util/zip/ZipInputStream.java Tue Feb 26 16:54:16 2013 +0100
1.3 @@ -0,0 +1,194 @@
1.4 +/*
1.5 + * Copyright (c) 1996, 2009, Oracle and/or its affiliates. All rights reserved.
1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1.7 + *
1.8 + * This code is free software; you can redistribute it and/or modify it
1.9 + * under the terms of the GNU General Public License version 2 only, as
1.10 + * published by the Free Software Foundation. Oracle designates this
1.11 + * particular file as subject to the "Classpath" exception as provided
1.12 + * by Oracle in the LICENSE file that accompanied this code.
1.13 + *
1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1.17 + * version 2 for more details (a copy is included in the LICENSE file that
1.18 + * accompanied this code).
1.19 + *
1.20 + * You should have received a copy of the GNU General Public License version
1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1.23 + *
1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1.25 + * or visit www.oracle.com if you need additional information or have any
1.26 + * questions.
1.27 + */
1.28 +
1.29 +package java.util.zip;
1.30 +
1.31 +import java.io.InputStream;
1.32 +import java.io.IOException;
1.33 +
1.34 +/**
1.35 + * This class implements an input stream filter for reading files in the
1.36 + * ZIP file format. Includes support for both compressed and uncompressed
1.37 + * entries.
1.38 + *
1.39 + * @author David Connelly
1.40 + */
1.41 +public
1.42 +class ZipInputStream extends InflaterInputStream implements ZipConstants {
1.43 + private final org.apidesign.bck2brwsr.emul.zip.ZipInputStream impl;
1.44 +
1.45 + /**
1.46 + * Creates a new ZIP input stream.
1.47 + *
1.48 + * <p>The UTF-8 {@link java.nio.charset.Charset charset} is used to
1.49 + * decode the entry names.
1.50 + *
1.51 + * @param in the actual input stream
1.52 + */
1.53 + public ZipInputStream(InputStream in) {
1.54 + super(in);
1.55 + impl = new org.apidesign.bck2brwsr.emul.zip.ZipInputStream(in);
1.56 + }
1.57 +
1.58 + /**
1.59 + * Creates a new ZIP input stream.
1.60 + *
1.61 + * @param in the actual input stream
1.62 + *
1.63 + * @param charset
1.64 + * The {@linkplain java.nio.charset.Charset charset} to be
1.65 + * used to decode the ZIP entry name (ignored if the
1.66 + * <a href="package-summary.html#lang_encoding"> language
1.67 + * encoding bit</a> of the ZIP entry's general purpose bit
1.68 + * flag is set).
1.69 + *
1.70 + * @since 1.7
1.71 + *
1.72 + public ZipInputStream(InputStream in, Charset charset) {
1.73 + super(new PushbackInputStream(in, 512), new Inflater(true), 512);
1.74 + usesDefaultInflater = true;
1.75 + if(in == null) {
1.76 + throw new NullPointerException("in is null");
1.77 + }
1.78 + if (charset == null)
1.79 + throw new NullPointerException("charset is null");
1.80 + this.zc = ZipCoder.get(charset);
1.81 + }
1.82 + */
1.83 +
1.84 + /**
1.85 + * Reads the next ZIP file entry and positions the stream at the
1.86 + * beginning of the entry data.
1.87 + * @return the next ZIP file entry, or null if there are no more entries
1.88 + * @exception ZipException if a ZIP file error has occurred
1.89 + * @exception IOException if an I/O error has occurred
1.90 + */
1.91 + public ZipEntry getNextEntry() throws IOException {
1.92 + return impl.getNextEntry();
1.93 + }
1.94 +
1.95 + /**
1.96 + * Closes the current ZIP entry and positions the stream for reading the
1.97 + * next entry.
1.98 + * @exception ZipException if a ZIP file error has occurred
1.99 + * @exception IOException if an I/O error has occurred
1.100 + */
1.101 + public void closeEntry() throws IOException {
1.102 + impl.closeEntry();
1.103 + }
1.104 +
1.105 + /**
1.106 + * Returns 0 after EOF has reached for the current entry data,
1.107 + * otherwise always return 1.
1.108 + * <p>
1.109 + * Programs should not count on this method to return the actual number
1.110 + * of bytes that could be read without blocking.
1.111 + *
1.112 + * @return 1 before EOF and 0 after EOF has reached for current entry.
1.113 + * @exception IOException if an I/O error occurs.
1.114 + *
1.115 + */
1.116 + public int available() throws IOException {
1.117 + return impl.available();
1.118 + }
1.119 +
1.120 + /**
1.121 + * Reads from the current ZIP entry into an array of bytes.
1.122 + * If <code>len</code> is not zero, the method
1.123 + * blocks until some input is available; otherwise, no
1.124 + * bytes are read and <code>0</code> is returned.
1.125 + * @param b the buffer into which the data is read
1.126 + * @param off the start offset in the destination array <code>b</code>
1.127 + * @param len the maximum number of bytes read
1.128 + * @return the actual number of bytes read, or -1 if the end of the
1.129 + * entry is reached
1.130 + * @exception NullPointerException if <code>b</code> is <code>null</code>.
1.131 + * @exception IndexOutOfBoundsException if <code>off</code> is negative,
1.132 + * <code>len</code> is negative, or <code>len</code> is greater than
1.133 + * <code>b.length - off</code>
1.134 + * @exception ZipException if a ZIP file error has occurred
1.135 + * @exception IOException if an I/O error has occurred
1.136 + */
1.137 + public int read(byte[] b, int off, int len) throws IOException {
1.138 + return impl.read(b, off, len);
1.139 + }
1.140 +
1.141 + /**
1.142 + * Skips specified number of bytes in the current ZIP entry.
1.143 + * @param n the number of bytes to skip
1.144 + * @return the actual number of bytes skipped
1.145 + * @exception ZipException if a ZIP file error has occurred
1.146 + * @exception IOException if an I/O error has occurred
1.147 + * @exception IllegalArgumentException if n < 0
1.148 + */
1.149 + public long skip(long n) throws IOException {
1.150 + return impl.skip(n);
1.151 + }
1.152 +
1.153 + /**
1.154 + * Closes this input stream and releases any system resources associated
1.155 + * with the stream.
1.156 + * @exception IOException if an I/O error has occurred
1.157 + */
1.158 + public void close() throws IOException {
1.159 + impl.close();
1.160 + }
1.161 +
1.162 + /**
1.163 + * Creates a new <code>ZipEntry</code> object for the specified
1.164 + * entry name.
1.165 + *
1.166 + * @param name the ZIP file entry name
1.167 + * @return the ZipEntry just created
1.168 + */
1.169 + protected ZipEntry createZipEntry(String name) {
1.170 + return new ZipEntry(name);
1.171 + }
1.172 +
1.173 + @Override
1.174 + public int read() throws IOException {
1.175 + return impl.read();
1.176 + }
1.177 +
1.178 + @Override
1.179 + public boolean markSupported() {
1.180 + return impl.markSupported();
1.181 + }
1.182 +
1.183 + @Override
1.184 + public void mark(int readlimit) {
1.185 + impl.mark(readlimit);
1.186 + }
1.187 +
1.188 + @Override
1.189 + public void reset() throws IOException {
1.190 + impl.reset();
1.191 + }
1.192 +
1.193 + @Override
1.194 + public int read(byte[] b) throws IOException {
1.195 + return impl.read(b);
1.196 + }
1.197 +}