src/java.base/share/classes/java/util/zip/ZipInputStream.java
author jboes
Tue, 24 Sep 2019 09:43:43 +0100
changeset 58288 48e480e56aad
parent 58242 94bb65cb37d3
child 58679 9c3209ff7550
child 59201 b24f4caa1411
permissions -rw-r--r--
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base Summary: Minor coding style update of javadoc tag in any file in java.base Reviewed-by: bchristi, lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
57670
cffcc4c5a5ba 8226530: ZipFile reads wrong entry size from ZIP64 entries
lancea
parents: 50238
diff changeset
     2
 * Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2704
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2704
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2704
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2704
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2704
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.util.zip;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.InputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.EOFException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.PushbackInputStream;
2592
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
    32
import java.nio.charset.Charset;
9676
5663e62f8d7e 7041612: Rename StandardCharset to StandardCharsets
mduigou
parents: 9526
diff changeset
    33
import java.nio.charset.StandardCharsets;
2438
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2
diff changeset
    34
import static java.util.zip.ZipConstants64.*;
17910
82d10099a8a6 4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents: 11828
diff changeset
    35
import static java.util.zip.ZipUtils.*;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * This class implements an input stream filter for reading files in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * ZIP file format. Includes support for both compressed and uncompressed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * entries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * @author      David Connelly
45434
4582657c7260 8181082: class-level since tag issues in java.base & java.datatransfer module
mli
parents: 29226
diff changeset
    43
 * @since 1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
public
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
class ZipInputStream extends InflaterInputStream implements ZipConstants {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private ZipEntry entry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private int flag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private CRC32 crc = new CRC32();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private long remaining;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private byte[] tmpbuf = new byte[512];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private static final int STORED = ZipEntry.STORED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private static final int DEFLATED = ZipEntry.DEFLATED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private boolean closed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    // this flag is set to true after EOF has reached for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    // one entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private boolean entryEOF = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
2592
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
    61
    private ZipCoder zc;
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
    62
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * Check to make sure that this stream has not been closed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private void ensureOpen() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        if (closed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            throw new IOException("Stream closed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * Creates a new ZIP input stream.
2592
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
    74
     *
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
    75
     * <p>The UTF-8 {@link java.nio.charset.Charset charset} is used to
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
    76
     * decode the entry names.
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
    77
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * @param in the actual input stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    public ZipInputStream(InputStream in) {
9676
5663e62f8d7e 7041612: Rename StandardCharset to StandardCharsets
mduigou
parents: 9526
diff changeset
    81
        this(in, StandardCharsets.UTF_8);
2592
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
    82
    }
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
    83
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
    84
    /**
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
    85
     * Creates a new ZIP input stream.
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
    86
     *
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
    87
     * @param in the actual input stream
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
    88
     *
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
    89
     * @param charset
2704
a92617170304 6836489: Incorrect @link usage in java.util.zip API doc
sherman
parents: 2592
diff changeset
    90
     *        The {@linkplain java.nio.charset.Charset charset} to be
2592
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
    91
     *        used to decode the ZIP entry name (ignored if the
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
    92
     *        <a href="package-summary.html#lang_encoding"> language
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
    93
     *        encoding bit</a> of the ZIP entry's general purpose bit
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
    94
     *        flag is set).
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
    95
     *
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
    96
     * @since 1.7
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
    97
     */
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
    98
    public ZipInputStream(InputStream in, Charset charset) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        super(new PushbackInputStream(in, 512), new Inflater(true), 512);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        usesDefaultInflater = true;
50238
a9307f400f5a 8203328: Rename EFS in java.util.zip internals to something meaningful
martin
parents: 47216
diff changeset
   101
        if (in == null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            throw new NullPointerException("in is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        }
2592
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   104
        if (charset == null)
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   105
            throw new NullPointerException("charset is null");
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   106
        this.zc = ZipCoder.get(charset);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * Reads the next ZIP file entry and positions the stream at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * beginning of the entry data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * @return the next ZIP file entry, or null if there are no more entries
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57670
diff changeset
   113
     * @throws    ZipException if a ZIP file error has occurred
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57670
diff changeset
   114
     * @throws    IOException if an I/O error has occurred
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    public ZipEntry getNextEntry() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        if (entry != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            closeEntry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        crc.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        inf.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        if ((entry = readLOC()) == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        if (entry.method == STORED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            remaining = entry.size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        entryEOF = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        return entry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * Closes the current ZIP entry and positions the stream for reading the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * next entry.
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57670
diff changeset
   136
     * @throws    ZipException if a ZIP file error has occurred
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57670
diff changeset
   137
     * @throws    IOException if an I/O error has occurred
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    public void closeEntry() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        while (read(tmpbuf, 0, tmpbuf.length) != -1) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        entryEOF = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * Returns 0 after EOF has reached for the current entry data,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * otherwise always return 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * Programs should not count on this method to return the actual number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * of bytes that could be read without blocking.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @return     1 before EOF and 0 after EOF has reached for current entry.
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57670
diff changeset
   153
     * @throws     IOException  if an I/O error occurs.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    public int available() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        if (entryEOF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * Reads from the current ZIP entry into an array of bytes.
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   167
     * If {@code len} is not zero, the method
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * blocks until some input is available; otherwise, no
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   169
     * bytes are read and {@code 0} is returned.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * @param b the buffer into which the data is read
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   171
     * @param off the start offset in the destination array {@code b}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @param len the maximum number of bytes read
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * @return the actual number of bytes read, or -1 if the end of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *         entry is reached
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   175
     * @throws     NullPointerException if {@code b} is {@code null}.
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   176
     * @throws     IndexOutOfBoundsException if {@code off} is negative,
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   177
     * {@code len} is negative, or {@code len} is greater than
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   178
     * {@code b.length - off}
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57670
diff changeset
   179
     * @throws    ZipException if a ZIP file error has occurred
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57670
diff changeset
   180
     * @throws    IOException if an I/O error has occurred
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    public int read(byte[] b, int off, int len) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        if (off < 0 || len < 0 || off > b.length - len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            throw new IndexOutOfBoundsException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        } else if (len == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        if (entry == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        switch (entry.method) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        case DEFLATED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            len = super.read(b, off, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            if (len == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                readEnd(entry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                entryEOF = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                entry = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                crc.update(b, off, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            return len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        case STORED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            if (remaining <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                entryEOF = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                entry = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            if (len > remaining) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                len = (int)remaining;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            len = in.read(b, off, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            if (len == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                throw new ZipException("unexpected EOF");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            crc.update(b, off, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            remaining -= len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            if (remaining == 0 && entry.crc != crc.getValue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                throw new ZipException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                    "invalid entry CRC (expected 0x" + Long.toHexString(entry.crc) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                    " but got 0x" + Long.toHexString(crc.getValue()) + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            return len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            throw new ZipException("invalid compression method");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * Skips specified number of bytes in the current ZIP entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @param n the number of bytes to skip
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @return the actual number of bytes skipped
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57670
diff changeset
   234
     * @throws    ZipException if a ZIP file error has occurred
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57670
diff changeset
   235
     * @throws    IOException if an I/O error has occurred
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57670
diff changeset
   236
     * @throws    IllegalArgumentException if {@code n < 0}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    public long skip(long n) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        if (n < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            throw new IllegalArgumentException("negative skip length");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        int max = (int)Math.min(n, Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        int total = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        while (total < max) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            int len = max - total;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            if (len > tmpbuf.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                len = tmpbuf.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            len = read(tmpbuf, 0, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            if (len == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                entryEOF = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            total += len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        return total;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * Closes this input stream and releases any system resources associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * with the stream.
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57670
diff changeset
   263
     * @throws    IOException if an I/O error has occurred
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    public void close() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        if (!closed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            super.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            closed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    private byte[] b = new byte[256];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * Reads local file (LOC) header for next entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    private ZipEntry readLOC() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            readFully(tmpbuf, 0, LOCHDR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        } catch (EOFException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        if (get32(tmpbuf, 0) != LOCSIG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        }
50238
a9307f400f5a 8203328: Rename EFS in java.util.zip internals to something meaningful
martin
parents: 47216
diff changeset
   286
        // get flag first, we need check USE_UTF8.
2592
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   287
        flag = get16(tmpbuf, LOCFLG);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        // get the entry name and create the ZipEntry first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        int len = get16(tmpbuf, LOCNAM);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        int blen = b.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        if (len > blen) {
19374
6773349693eb 8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents: 18156
diff changeset
   292
            do {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                blen = blen * 2;
19374
6773349693eb 8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents: 18156
diff changeset
   294
            } while (len > blen);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            b = new byte[blen];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        readFully(b, 0, len);
50238
a9307f400f5a 8203328: Rename EFS in java.util.zip internals to something meaningful
martin
parents: 47216
diff changeset
   298
        // Force to use UTF-8 if the USE_UTF8 bit is ON
a9307f400f5a 8203328: Rename EFS in java.util.zip internals to something meaningful
martin
parents: 47216
diff changeset
   299
        ZipEntry e = createZipEntry(((flag & USE_UTF8) != 0)
2592
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   300
                                    ? zc.toStringUTF8(b, len)
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   301
                                    : zc.toString(b, len));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        // now get the remaining fields for the entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        if ((flag & 1) == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            throw new ZipException("encrypted ZIP entry not supported");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        e.method = get16(tmpbuf, LOCHOW);
29226
b675016fabfd 8073497: Lazy conversion of ZipEntry time
redestad
parents: 26615
diff changeset
   307
        e.xdostime = get32(tmpbuf, LOCTIM);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        if ((flag & 8) == 8) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            /* "Data Descriptor" present */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            if (e.method != DEFLATED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                throw new ZipException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                        "only DEFLATED entries can have EXT descriptor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            e.crc = get32(tmpbuf, LOCCRC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            e.csize = get32(tmpbuf, LOCSIZ);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            e.size = get32(tmpbuf, LOCLEN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        len = get16(tmpbuf, LOCEXT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        if (len > 0) {
17910
82d10099a8a6 4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents: 11828
diff changeset
   321
            byte[] extra = new byte[len];
82d10099a8a6 4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents: 11828
diff changeset
   322
            readFully(extra, 0, len);
24711
796059d86950 8044727: Problem reading the contents of some zip files
sherman
parents: 19374
diff changeset
   323
            e.setExtra0(extra,
57670
cffcc4c5a5ba 8226530: ZipFile reads wrong entry size from ZIP64 entries
lancea
parents: 50238
diff changeset
   324
                        e.csize == ZIP64_MAGICVAL || e.size == ZIP64_MAGICVAL, true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        return e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    /**
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   330
     * Creates a new {@code ZipEntry} object for the specified
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * entry name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * @param name the ZIP file entry name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * @return the ZipEntry just created
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    protected ZipEntry createZipEntry(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        return new ZipEntry(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
26615
faabac3002f1 8056934: ZipInputStream does not correctly handle local header data descriptors with the optional signature missing
martin
parents: 25859
diff changeset
   340
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * Reads end of deflated entry as well as EXT descriptor if present.
26615
faabac3002f1 8056934: ZipInputStream does not correctly handle local header data descriptors with the optional signature missing
martin
parents: 25859
diff changeset
   342
     *
faabac3002f1 8056934: ZipInputStream does not correctly handle local header data descriptors with the optional signature missing
martin
parents: 25859
diff changeset
   343
     * Local headers for DEFLATED entries may optionally be followed by a
faabac3002f1 8056934: ZipInputStream does not correctly handle local header data descriptors with the optional signature missing
martin
parents: 25859
diff changeset
   344
     * data descriptor, and that data descriptor may optionally contain a
faabac3002f1 8056934: ZipInputStream does not correctly handle local header data descriptors with the optional signature missing
martin
parents: 25859
diff changeset
   345
     * leading signature (EXTSIG).
faabac3002f1 8056934: ZipInputStream does not correctly handle local header data descriptors with the optional signature missing
martin
parents: 25859
diff changeset
   346
     *
faabac3002f1 8056934: ZipInputStream does not correctly handle local header data descriptors with the optional signature missing
martin
parents: 25859
diff changeset
   347
     * From the zip spec http://www.pkware.com/documents/casestudies/APPNOTE.TXT
faabac3002f1 8056934: ZipInputStream does not correctly handle local header data descriptors with the optional signature missing
martin
parents: 25859
diff changeset
   348
     *
faabac3002f1 8056934: ZipInputStream does not correctly handle local header data descriptors with the optional signature missing
martin
parents: 25859
diff changeset
   349
     * """Although not originally assigned a signature, the value 0x08074b50
faabac3002f1 8056934: ZipInputStream does not correctly handle local header data descriptors with the optional signature missing
martin
parents: 25859
diff changeset
   350
     * has commonly been adopted as a signature value for the data descriptor
faabac3002f1 8056934: ZipInputStream does not correctly handle local header data descriptors with the optional signature missing
martin
parents: 25859
diff changeset
   351
     * record.  Implementers should be aware that ZIP files may be
faabac3002f1 8056934: ZipInputStream does not correctly handle local header data descriptors with the optional signature missing
martin
parents: 25859
diff changeset
   352
     * encountered with or without this signature marking data descriptors
faabac3002f1 8056934: ZipInputStream does not correctly handle local header data descriptors with the optional signature missing
martin
parents: 25859
diff changeset
   353
     * and should account for either case when reading ZIP files to ensure
faabac3002f1 8056934: ZipInputStream does not correctly handle local header data descriptors with the optional signature missing
martin
parents: 25859
diff changeset
   354
     * compatibility."""
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    private void readEnd(ZipEntry e) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        int n = inf.getRemaining();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        if (n > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            ((PushbackInputStream)in).unread(buf, len - n, n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        if ((flag & 8) == 8) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            /* "Data Descriptor" present */
2438
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2
diff changeset
   363
            if (inf.getBytesWritten() > ZIP64_MAGICVAL ||
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2
diff changeset
   364
                inf.getBytesRead() > ZIP64_MAGICVAL) {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2
diff changeset
   365
                // ZIP64 format
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2
diff changeset
   366
                readFully(tmpbuf, 0, ZIP64_EXTHDR);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2
diff changeset
   367
                long sig = get32(tmpbuf, 0);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2
diff changeset
   368
                if (sig != EXTSIG) { // no EXTSIG present
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2
diff changeset
   369
                    e.crc = sig;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2
diff changeset
   370
                    e.csize = get64(tmpbuf, ZIP64_EXTSIZ - ZIP64_EXTCRC);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2
diff changeset
   371
                    e.size = get64(tmpbuf, ZIP64_EXTLEN - ZIP64_EXTCRC);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2
diff changeset
   372
                    ((PushbackInputStream)in).unread(
26615
faabac3002f1 8056934: ZipInputStream does not correctly handle local header data descriptors with the optional signature missing
martin
parents: 25859
diff changeset
   373
                        tmpbuf, ZIP64_EXTHDR - ZIP64_EXTCRC, ZIP64_EXTCRC);
2438
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2
diff changeset
   374
                } else {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2
diff changeset
   375
                    e.crc = get32(tmpbuf, ZIP64_EXTCRC);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2
diff changeset
   376
                    e.csize = get64(tmpbuf, ZIP64_EXTSIZ);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2
diff changeset
   377
                    e.size = get64(tmpbuf, ZIP64_EXTLEN);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2
diff changeset
   378
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            } else {
2438
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2
diff changeset
   380
                readFully(tmpbuf, 0, EXTHDR);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2
diff changeset
   381
                long sig = get32(tmpbuf, 0);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2
diff changeset
   382
                if (sig != EXTSIG) { // no EXTSIG present
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2
diff changeset
   383
                    e.crc = sig;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2
diff changeset
   384
                    e.csize = get32(tmpbuf, EXTSIZ - EXTCRC);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2
diff changeset
   385
                    e.size = get32(tmpbuf, EXTLEN - EXTCRC);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2
diff changeset
   386
                    ((PushbackInputStream)in).unread(
26615
faabac3002f1 8056934: ZipInputStream does not correctly handle local header data descriptors with the optional signature missing
martin
parents: 25859
diff changeset
   387
                                               tmpbuf, EXTHDR - EXTCRC, EXTCRC);
2438
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2
diff changeset
   388
                } else {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2
diff changeset
   389
                    e.crc = get32(tmpbuf, EXTCRC);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2
diff changeset
   390
                    e.csize = get32(tmpbuf, EXTSIZ);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2
diff changeset
   391
                    e.size = get32(tmpbuf, EXTLEN);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2
diff changeset
   392
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        if (e.size != inf.getBytesWritten()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            throw new ZipException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                "invalid entry size (expected " + e.size +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                " but got " + inf.getBytesWritten() + " bytes)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        if (e.csize != inf.getBytesRead()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            throw new ZipException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                "invalid entry compressed size (expected " + e.csize +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                " but got " + inf.getBytesRead() + " bytes)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        if (e.crc != crc.getValue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            throw new ZipException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                "invalid entry CRC (expected 0x" + Long.toHexString(e.crc) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                " but got 0x" + Long.toHexString(crc.getValue()) + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * Reads bytes, blocking until all bytes are read.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    private void readFully(byte[] b, int off, int len) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        while (len > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            int n = in.read(b, off, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            if (n == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                throw new EOFException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            off += n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            len -= n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
}