jdk/src/share/classes/java/net/JarURLConnection.java
author malenkov
Tue, 29 Oct 2013 17:01:06 +0400
changeset 21278 ef8a3a2a72f2
parent 19069 1d9cb0d080e3
permissions -rw-r--r--
8022746: List of spelling errors in API doc Reviewed-by: alexsch, smarks
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 5506
diff changeset
     2
 * Copyright (c) 1997, 2013, 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++));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        entryName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        /* if ! is the last letter of the innerURL, entryName is null */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        if (++separator != spec.length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            entryName = spec.substring(separator, spec.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            entryName = ParseUtil.decode (entryName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * Returns the URL for the Jar file for this connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * @return the URL for the Jar file for this connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    public URL getJarFileURL() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        return jarFileURL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * Return the entry name for this connection. This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * returns null if the JAR file URL corresponding to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * connection points to a JAR file and not a JAR file entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @return the entry name for this connection, if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    public String getEntryName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        return entryName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * Return the JAR file for this connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * @return the JAR file for this connection. If the connection is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * a connection to an entry of a JAR file, the JAR file object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * @exception IOException if an IOException occurs while trying to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * connect to the JAR file for this connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @see #connect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    public abstract JarFile getJarFile() throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * Returns the Manifest for this connection, or null if none.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * @return the manifest object corresponding to the JAR file object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * for this connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @exception IOException if getting the JAR file for this
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 19069
diff changeset
   226
     * connection causes an IOException to be thrown.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * @see #getJarFile
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    public Manifest getManifest() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        return getJarFile().getManifest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * Return the JAR entry object for this connection, if any. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * method returns null if the JAR file URL corresponding to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * connection points to a JAR file and not a JAR file entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * @return the JAR entry object for this connection, or null if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * the JAR URL for this connection points to a JAR file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * @exception IOException if getting the JAR file for this
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 19069
diff changeset
   243
     * connection causes an IOException to be thrown.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * @see #getJarFile
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * @see #getJarEntry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    public JarEntry getJarEntry() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        return getJarFile().getJarEntry(entryName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * Return the Attributes object for this connection if the URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * for it points to a JAR file entry, null otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @return the Attributes object for this connection if the URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * for it points to a JAR file entry, null otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * @exception IOException if getting the JAR entry causes an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * IOException to be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * @see #getJarEntry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    public Attributes getAttributes() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        JarEntry e = getJarEntry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        return e != null ? e.getAttributes() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * Returns the main Attributes for the JAR file for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * @return the main Attributes for the JAR file for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * @exception IOException if getting the manifest causes an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * IOException to be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @see #getJarFile
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @see #getManifest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    public Attributes getMainAttributes() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        Manifest man = getManifest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        return man != null ? man.getMainAttributes() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * Return the Certificate object for this connection if the URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * for it points to a JAR file entry, null otherwise. This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * can only be called once
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * the connection has been completely verified by reading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * 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
   293
     * reached. Otherwise, this method will return {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * @return the Certificate object for this connection if the URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * for it points to a JAR file entry, null otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * @exception IOException if getting the JAR entry causes an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * IOException to be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * @see #getJarEntry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    public java.security.cert.Certificate[] getCertificates()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
         throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        JarEntry e = getJarEntry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        return e != null ? e.getCertificates() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
}