src/java.base/share/classes/java/net/JarURLConnection.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 58242 94bb65cb37d3
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
/*
54068
b067bd7edc26 8184315: Typo in java.net.JarURLConnection.getCertificates() method documentation
chegar
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.net;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.jar.JarFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.jar.JarEntry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.jar.Attributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.jar.Manifest;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.security.Permission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import sun.net.www.ParseUtil;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * A URL Connection to a Java ARchive (JAR) file or an entry in a JAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * <p>The syntax of a JAR URL is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * jar:&lt;url&gt;!/{entry}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <p>for example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 5506
diff changeset
    48
 * <p>{@code jar:http://www.foo.com/bar/baz.jar!/COM/foo/Quux.class}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <p>Jar URLs should be used to refer to a JAR file or entries in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * a JAR file. The example above is a JAR URL which refers to a JAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * entry. If the entry name is omitted, the URL refers to the whole
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * JAR file:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 5506
diff changeset
    55
 * {@code jar:http://www.foo.com/bar/baz.jar!/}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <p>Users should cast the generic URLConnection to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * JarURLConnection when they know that the URL they created is a JAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * URL, and they need JAR-specific functionality. For example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * URL url = new URL("jar:file:/home/duke/duke.jar!/");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * JarURLConnection jarConnection = (JarURLConnection)url.openConnection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * Manifest manifest = jarConnection.getManifest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * <p>JarURLConnection instances can only be used to read from JAR files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * It is not possible to get a {@link java.io.OutputStream} to modify or write
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * to the underlying JAR file using this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * <p>Examples:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * <dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * <dt>A Jar entry
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 5506
diff changeset
    75
 * <dd>{@code jar:http://www.foo.com/bar/baz.jar!/COM/foo/Quux.class}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * <dt>A Jar file
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 5506
diff changeset
    78
 * <dd>{@code jar:http://www.foo.com/bar/baz.jar!/}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * <dt>A Jar directory
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 5506
diff changeset
    81
 * <dd>{@code jar:http://www.foo.com/bar/baz.jar!/COM/foo/}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * </dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 19069
diff changeset
    85
 * <p>{@code !/} is referred to as the <em>separator</em>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 *
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 5506
diff changeset
    87
 * <p>When constructing a JAR url via {@code new URL(context, spec)},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * the following rules apply:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * <li>if there is no context URL and the specification passed to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * URL constructor doesn't contain a separator, the URL is considered
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * to refer to a JarFile.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * <li>if there is a context URL, the context URL is assumed to refer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * to a JAR file or a Jar directory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * <li>if the specification begins with a '/', the Jar directory is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * ignored, and the spec is considered to be at the root of the Jar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * <p>Examples:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * <dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * <dt>context: <b>jar:http://www.foo.com/bar/jar.jar!/</b>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * spec:<b>baz/entry.txt</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * <dd>url:<b>jar:http://www.foo.com/bar/jar.jar!/baz/entry.txt</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * <dt>context: <b>jar:http://www.foo.com/bar/jar.jar!/baz</b>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * spec:<b>entry.txt</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * <dd>url:<b>jar:http://www.foo.com/bar/jar.jar!/baz/entry.txt</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * <dt>context: <b>jar:http://www.foo.com/bar/jar.jar!/baz</b>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * spec:<b>/entry.txt</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * <dd>url:<b>jar:http://www.foo.com/bar/jar.jar!/entry.txt</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * </dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * @see java.net.URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 * @see java.net.URLConnection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 * @see java.util.jar.JarFile
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 * @see java.util.jar.JarInputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * @see java.util.jar.Manifest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 * @see java.util.zip.ZipEntry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * @author Benjamin Renaud
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
public abstract class JarURLConnection extends URLConnection {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    private URL jarFileURL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    private String entryName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * The connection to the JAR file URL, if the connection has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * initiated. This should be set by connect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    protected URLConnection jarFileURLConnection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * Creates the new JarURLConnection to the specified URL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * @param url the URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * @throws MalformedURLException if no legal protocol
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * could be found in a specification string or the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * string could not be parsed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    protected JarURLConnection(URL url) throws MalformedURLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        super(url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        parseSpecs(url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    /* get the specs for a given url out of the cache, and compute and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * cache them if they're not there.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    private void parseSpecs(URL url) throws MalformedURLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        String spec = url.getFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        int separator = spec.indexOf("!/");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
         * REMIND: we don't handle nested JAR URLs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        if (separator == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            throw new MalformedURLException("no !/ found in url spec:" + spec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        jarFileURL = new URL(spec.substring(0, separator++));
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 25859
diff changeset
   176
        /*
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 25859
diff changeset
   177
         * The url argument may have had a runtime fragment appended, so
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 25859
diff changeset
   178
         * we need to add a runtime fragment to the jarFileURL to enable
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 25859
diff changeset
   179
         * runtime versioning when the underlying jar file is opened.
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 25859
diff changeset
   180
         */
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 25859
diff changeset
   181
        if ("runtime".equals(url.getRef())) {
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 25859
diff changeset
   182
            jarFileURL = new URL(jarFileURL, "#runtime");
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 25859
diff changeset
   183
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        entryName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        /* if ! is the last letter of the innerURL, entryName is null */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        if (++separator != spec.length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            entryName = spec.substring(separator, spec.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            entryName = ParseUtil.decode (entryName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * Returns the URL for the Jar file for this connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @return the URL for the Jar file for this connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    public URL getJarFileURL() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        return jarFileURL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * Return the entry name for this connection. This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * returns null if the JAR file URL corresponding to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * connection points to a JAR file and not a JAR file entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * @return the entry name for this connection, if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    public String getEntryName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        return entryName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * Return the JAR file for this connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * @return the JAR file for this connection. If the connection is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * a connection to an entry of a JAR file, the JAR file object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 55228
diff changeset
   220
     * @throws    IOException if an IOException occurs while trying to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * connect to the JAR file for this connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * @see #connect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    public abstract JarFile getJarFile() throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * Returns the Manifest for this connection, or null if none.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * @return the manifest object corresponding to the JAR file object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * for this connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     *
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 55228
diff changeset
   233
     * @throws    IOException if getting the JAR file for this
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 19069
diff changeset
   234
     * connection causes an IOException to be thrown.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * @see #getJarFile
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    public Manifest getManifest() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        return getJarFile().getManifest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * Return the JAR entry object for this connection, if any. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * method returns null if the JAR file URL corresponding to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * connection points to a JAR file and not a JAR file entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * @return the JAR entry object for this connection, or null if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * the JAR URL for this connection points to a JAR file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     *
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 55228
diff changeset
   250
     * @throws    IOException if getting the JAR file for this
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 19069
diff changeset
   251
     * connection causes an IOException to be thrown.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * @see #getJarFile
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * @see #getJarEntry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    public JarEntry getJarEntry() throws IOException {
55228
ec621f7f95f2 8225037: java.net.JarURLConnection::getJarEntry() throws NullPointerException
chegar
parents: 54068
diff changeset
   257
        return entryName == null ? null : getJarFile().getJarEntry(entryName);
2
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
     * Return the Attributes object for this connection if the URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * for it points to a JAR file entry, null otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * @return the Attributes object for this connection if the URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * for it points to a JAR file entry, null otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     *
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 55228
diff changeset
   267
     * @throws    IOException if getting the JAR entry causes an
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * IOException to be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * @see #getJarEntry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    public Attributes getAttributes() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        JarEntry e = getJarEntry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        return e != null ? e.getAttributes() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * Returns the main Attributes for the JAR file for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * @return the main Attributes for the JAR file for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     *
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 55228
diff changeset
   284
     * @throws    IOException if getting the manifest causes an
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * IOException to be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * @see #getJarFile
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * @see #getManifest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    public Attributes getMainAttributes() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        Manifest man = getManifest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        return man != null ? man.getMainAttributes() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    /**
54068
b067bd7edc26 8184315: Typo in java.net.JarURLConnection.getCertificates() method documentation
chegar
parents: 47216
diff changeset
   296
     * Returns the Certificate objects for this connection if the URL
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * for it points to a JAR file entry, null otherwise. This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * can only be called once
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * the connection has been completely verified by reading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * from the input stream until the end of the stream has been
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 5506
diff changeset
   301
     * reached. Otherwise, this method will return {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * @return the Certificate object for this connection if the URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * for it points to a JAR file entry, null otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     *
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 55228
diff changeset
   306
     * @throws    IOException if getting the JAR entry causes an
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * IOException to be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * @see #getJarEntry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    public java.security.cert.Certificate[] getCertificates()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
         throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        JarEntry e = getJarEntry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        return e != null ? e.getCertificates() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
}