< prev index next >

src/java.base/share/classes/java/util/zip/ZipInputStream.java

Print this page
rev 49550 : 8201179: Regression due loading java.nio.charset.StandardCharsets during bootstrap
Reviewed-by: sherman


  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 import static java.util.zip.ZipUtils.*;
  36 


  37 /**
  38  * This class implements an input stream filter for reading files in the
  39  * ZIP file format. Includes support for both compressed and uncompressed
  40  * entries.
  41  *
  42  * @author      David Connelly
  43  * @since 1.1
  44  */
  45 public
  46 class ZipInputStream extends InflaterInputStream implements ZipConstants {
  47     private ZipEntry entry;
  48     private int flag;
  49     private CRC32 crc = new CRC32();
  50     private long remaining;
  51     private byte[] tmpbuf = new byte[512];
  52 
  53     private static final int STORED = ZipEntry.STORED;
  54     private static final int DEFLATED = ZipEntry.DEFLATED;
  55 
  56     private boolean closed = false;


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


  62     private ZipCoder zc;
  63 
  64     /**
  65      * Check to make sure that this stream has not been closed
  66      */
  67     private void ensureOpen() throws IOException {
  68         if (closed) {
  69             throw new IOException("Stream closed");
  70         }
  71     }
  72 
  73     /**
  74      * Creates a new ZIP input stream.
  75      *
  76      * <p>The UTF-8 {@link java.nio.charset.Charset charset} is used to
  77      * decode the entry names.
  78      *
  79      * @param in the actual input stream
  80      */
  81     public ZipInputStream(InputStream in) {
  82         this(in, UTF_8.INSTANCE);
  83     }
  84 
  85     /**
  86      * Creates a new ZIP input stream.
  87      *
  88      * @param in the actual input stream
  89      *
  90      * @param charset
  91      *        The {@linkplain java.nio.charset.Charset charset} to be
  92      *        used to decode the ZIP entry name (ignored if the
  93      *        <a href="package-summary.html#lang_encoding"> language
  94      *        encoding bit</a> of the ZIP entry's general purpose bit
  95      *        flag is set).
  96      *
  97      * @since 1.7
  98      */
  99     public ZipInputStream(InputStream in, Charset charset) {
 100         super(new PushbackInputStream(in, 512), new Inflater(true), 512);
 101         usesDefaultInflater = true;
 102         if(in == null) {


< prev index next >