src/java.base/share/classes/java/util/jar/JarInputStream.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 58288 48e480e56aad
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
     2
 * Copyright (c) 1997, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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.jar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.zip.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import sun.security.util.ManifestEntryVerifier;
36745
51effd3e92d0 8152190: Move sun.misc.JarIndex and InvalidJarIndexException to an internal package
chegar
parents: 25859
diff changeset
    31
import jdk.internal.util.jar.JarIndex;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
    34
 * The {@code JarInputStream} class is used to read the contents of
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * a JAR file from any input stream. It extends the class
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
    36
 * {@code java.util.zip.ZipInputStream} with support for reading
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
    37
 * an optional {@code Manifest} entry. The {@code Manifest}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * can be used to store meta-information about the JAR file and its entries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * @author  David Connelly
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * @see     Manifest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * @see     java.util.zip.ZipInputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * @since   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 JarInputStream extends ZipInputStream {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private Manifest man;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private JarEntry first;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private JarVerifier jv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private ManifestEntryVerifier mev;
7190
2bd7f94e734d 6544278: SecurityException not thrown for Indexed Jar file whose signature is corrupted
sherman
parents: 5506
diff changeset
    51
    private final boolean doVerify;
2bd7f94e734d 6544278: SecurityException not thrown for Indexed Jar file whose signature is corrupted
sherman
parents: 5506
diff changeset
    52
    private boolean tryManifest;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    /**
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
    55
     * Creates a new {@code JarInputStream} and reads the optional
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * manifest. If a manifest is present, also attempts to verify
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * the signatures if the JarInputStream is signed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * @param in the actual input stream
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
    59
     * @throws    IOException if an I/O error has occurred
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    public JarInputStream(InputStream in) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        this(in, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    /**
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
    66
     * Creates a new {@code JarInputStream} and reads the optional
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * manifest. If a manifest is present and verify is true, also attempts
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * to verify the signatures if the JarInputStream is signed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * @param in the actual input stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * @param verify whether or not to verify the JarInputStream if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * it is signed.
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
    73
     * @throws    IOException if an I/O error has occurred
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    public JarInputStream(InputStream in, boolean verify) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        super(in);
7190
2bd7f94e734d 6544278: SecurityException not thrown for Indexed Jar file whose signature is corrupted
sherman
parents: 5506
diff changeset
    77
        this.doVerify = verify;
2bd7f94e734d 6544278: SecurityException not thrown for Indexed Jar file whose signature is corrupted
sherman
parents: 5506
diff changeset
    78
2bd7f94e734d 6544278: SecurityException not thrown for Indexed Jar file whose signature is corrupted
sherman
parents: 5506
diff changeset
    79
        // This implementation assumes the META-INF/MANIFEST.MF entry
2bd7f94e734d 6544278: SecurityException not thrown for Indexed Jar file whose signature is corrupted
sherman
parents: 5506
diff changeset
    80
        // should be either the first or the second entry (when preceded
2bd7f94e734d 6544278: SecurityException not thrown for Indexed Jar file whose signature is corrupted
sherman
parents: 5506
diff changeset
    81
        // by the dir META-INF/). It skips the META-INF/ and then
2bd7f94e734d 6544278: SecurityException not thrown for Indexed Jar file whose signature is corrupted
sherman
parents: 5506
diff changeset
    82
        // "consumes" the MANIFEST.MF to initialize the Manifest object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        JarEntry e = (JarEntry)super.getNextEntry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        if (e != null && e.getName().equalsIgnoreCase("META-INF/"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            e = (JarEntry)super.getNextEntry();
7190
2bd7f94e734d 6544278: SecurityException not thrown for Indexed Jar file whose signature is corrupted
sherman
parents: 5506
diff changeset
    86
        first = checkManifest(e);
2bd7f94e734d 6544278: SecurityException not thrown for Indexed Jar file whose signature is corrupted
sherman
parents: 5506
diff changeset
    87
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
7190
2bd7f94e734d 6544278: SecurityException not thrown for Indexed Jar file whose signature is corrupted
sherman
parents: 5506
diff changeset
    89
    private JarEntry checkManifest(JarEntry e)
2bd7f94e734d 6544278: SecurityException not thrown for Indexed Jar file whose signature is corrupted
sherman
parents: 5506
diff changeset
    90
        throws IOException
2bd7f94e734d 6544278: SecurityException not thrown for Indexed Jar file whose signature is corrupted
sherman
parents: 5506
diff changeset
    91
    {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        if (e != null && JarFile.MANIFEST_NAME.equalsIgnoreCase(e.getName())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            man = new Manifest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            byte bytes[] = getBytes(new BufferedInputStream(this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            man.read(new ByteArrayInputStream(bytes));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            closeEntry();
7190
2bd7f94e734d 6544278: SecurityException not thrown for Indexed Jar file whose signature is corrupted
sherman
parents: 5506
diff changeset
    97
            if (doVerify) {
9365
469cd39a25de 7040803: regression: bugster fail to start
igor
parents: 9248
diff changeset
    98
                jv = new JarVerifier(bytes);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                mev = new ManifestEntryVerifier(man);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            }
7190
2bd7f94e734d 6544278: SecurityException not thrown for Indexed Jar file whose signature is corrupted
sherman
parents: 5506
diff changeset
   101
            return (JarEntry)super.getNextEntry();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        }
7190
2bd7f94e734d 6544278: SecurityException not thrown for Indexed Jar file whose signature is corrupted
sherman
parents: 5506
diff changeset
   103
        return e;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    private byte[] getBytes(InputStream is)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        byte[] buffer = new byte[8192];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        ByteArrayOutputStream baos = new ByteArrayOutputStream(2048);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        int n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        while ((n = is.read(buffer, 0, buffer.length)) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            baos.write(buffer, 0, n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        return baos.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    /**
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   119
     * Returns the {@code Manifest} for this JAR file, or
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   120
     * {@code null} if none.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     *
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   122
     * @return the {@code Manifest} for this JAR file, or
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   123
     *         {@code null} if none.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    public Manifest getManifest() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        return man;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * Reads the next ZIP file entry and positions the stream at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * beginning of the entry data. If verification has been enabled,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * any invalid signature detected while positioning the stream for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * the next entry will result in an exception.
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
   134
     * @throws    ZipException if a ZIP file error has occurred
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
   135
     * @throws    IOException if an I/O error has occurred
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
   136
     * @throws    SecurityException if any of the jar file entries
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *         are incorrectly signed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    public ZipEntry getNextEntry() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        JarEntry e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        if (first == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            e = (JarEntry)super.getNextEntry();
7190
2bd7f94e734d 6544278: SecurityException not thrown for Indexed Jar file whose signature is corrupted
sherman
parents: 5506
diff changeset
   143
            if (tryManifest) {
2bd7f94e734d 6544278: SecurityException not thrown for Indexed Jar file whose signature is corrupted
sherman
parents: 5506
diff changeset
   144
                e = checkManifest(e);
2bd7f94e734d 6544278: SecurityException not thrown for Indexed Jar file whose signature is corrupted
sherman
parents: 5506
diff changeset
   145
                tryManifest = false;
2bd7f94e734d 6544278: SecurityException not thrown for Indexed Jar file whose signature is corrupted
sherman
parents: 5506
diff changeset
   146
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            e = first;
7190
2bd7f94e734d 6544278: SecurityException not thrown for Indexed Jar file whose signature is corrupted
sherman
parents: 5506
diff changeset
   149
            if (first.getName().equalsIgnoreCase(JarIndex.INDEX_NAME))
2bd7f94e734d 6544278: SecurityException not thrown for Indexed Jar file whose signature is corrupted
sherman
parents: 5506
diff changeset
   150
                tryManifest = true;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            first = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        if (jv != null && e != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            // At this point, we might have parsed all the meta-inf
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            // entries and have nothing to verify. If we have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            // nothing to verify, get rid of the JarVerifier object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            if (jv.nothingToVerify() == true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                jv = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                mev = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                jv.beginEntry(e, mev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        return e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * Reads the next JAR file entry and positions the stream at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * beginning of the entry data. If verification has been enabled,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * any invalid signature detected while positioning the stream for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * the next entry will result in an exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @return the next JAR file entry, or null if there are no more entries
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
   173
     * @throws    ZipException if a ZIP file error has occurred
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
   174
     * @throws    IOException if an I/O error has occurred
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
   175
     * @throws    SecurityException if any of the jar file entries
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *         are incorrectly signed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    public JarEntry getNextJarEntry() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        return (JarEntry)getNextEntry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * Reads from the current JAR file 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
   184
     * If {@code len} is not zero, the method
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * 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
   186
     * bytes are read and {@code 0} is returned.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * If verification has been enabled, any invalid signature
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * on the current entry will be reported at some point before the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * end of the entry is reached.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * @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
   191
     * @param off the start offset in the destination array {@code b}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * @param len the maximum number of bytes to read
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * @return the actual number of bytes read, or -1 if the end of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     *         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
   195
     * @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
   196
     * @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
   197
     * {@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
   198
     * {@code b.length - off}
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
   199
     * @throws    ZipException if a ZIP file error has occurred
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
   200
     * @throws    IOException if an I/O error has occurred
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
   201
     * @throws    SecurityException if any of the jar file entries
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *         are incorrectly signed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    public int read(byte[] b, int off, int len) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        int n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        if (first == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            n = super.read(b, off, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            n = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        if (jv != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            jv.update(n, b, off, len, mev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        return n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    /**
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   218
     * Creates a new {@code JarEntry} ({@code ZipEntry}) for the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * specified JAR file entry name. The manifest attributes of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * the specified JAR file entry name will be copied to the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * <CODE>JarEntry</CODE>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * @param name the name of the JAR/ZIP file entry
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   224
     * @return the {@code JarEntry} object just created
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    protected ZipEntry createZipEntry(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        JarEntry e = new JarEntry(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        if (man != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            e.attr = man.getAttributes(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        return e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
}