jdk/src/share/classes/java/net/JarURLConnection.java
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 2 90ce3da70b43
child 19069 1d9cb0d080e3
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1997, 2006, 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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <p><code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * jar:http://www.foo.com/bar/baz.jar!/COM/foo/Quux.class<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * </code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <p>Jar URLs should be used to refer to a JAR file or entries in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * a JAR file. The example above is a JAR URL which refers to a JAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * entry. If the entry name is omitted, the URL refers to the whole
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * JAR file:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * jar:http://www.foo.com/bar/baz.jar!/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * </code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <p>Users should cast the generic URLConnection to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * JarURLConnection when they know that the URL they created is a JAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * URL, and they need JAR-specific functionality. For example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * URL url = new URL("jar:file:/home/duke/duke.jar!/");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * JarURLConnection jarConnection = (JarURLConnection)url.openConnection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * Manifest manifest = jarConnection.getManifest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * <p>JarURLConnection instances can only be used to read from JAR files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * It is not possible to get a {@link java.io.OutputStream} to modify or write
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * to the underlying JAR file using this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * <p>Examples:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * <dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * <dt>A Jar entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * <dd><code>jar:http://www.foo.com/bar/baz.jar!/COM/foo/Quux.class</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * <dt>A Jar file
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * <dd><code>jar:http://www.foo.com/bar/baz.jar!/</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * <dt>A Jar directory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * <dd><code>jar:http://www.foo.com/bar/baz.jar!/COM/foo/</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * </dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * <p><code>!/</code> is refered to as the <em>separator</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * <p>When constructing a JAR url via <code>new URL(context, spec)</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * the following rules apply:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * <li>if there is no context URL and the specification passed to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * URL constructor doesn't contain a separator, the URL is considered
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * to refer to a JarFile.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * <li>if there is a context URL, the context URL is assumed to refer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * to a JAR file or a Jar directory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * <li>if the specification begins with a '/', the Jar directory is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * ignored, and the spec is considered to be at the root of the Jar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * <p>Examples:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * <dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * <dt>context: <b>jar:http://www.foo.com/bar/jar.jar!/</b>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * spec:<b>baz/entry.txt</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * <dd>url:<b>jar:http://www.foo.com/bar/jar.jar!/baz/entry.txt</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * <dt>context: <b>jar:http://www.foo.com/bar/jar.jar!/baz</b>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * spec:<b>entry.txt</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * <dd>url:<b>jar:http://www.foo.com/bar/jar.jar!/baz/entry.txt</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * <dt>context: <b>jar:http://www.foo.com/bar/jar.jar!/baz</b>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * spec:<b>/entry.txt</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * <dd>url:<b>jar:http://www.foo.com/bar/jar.jar!/entry.txt</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * </dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 * @see java.net.URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * @see java.net.URLConnection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 * @see java.util.jar.JarFile
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * @see java.util.jar.JarInputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * @see java.util.jar.Manifest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 * @see java.util.zip.ZipEntry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 * @author Benjamin Renaud
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
public abstract class JarURLConnection extends URLConnection {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    private URL jarFileURL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    private String entryName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * The connection to the JAR file URL, if the connection has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * initiated. This should be set by connect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    protected URLConnection jarFileURLConnection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * Creates the new JarURLConnection to the specified URL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @param url the URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * @throws MalformedURLException if no legal protocol
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * could be found in a specification string or the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * string could not be parsed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    protected JarURLConnection(URL url) throws MalformedURLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        super(url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        parseSpecs(url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    /* get the specs for a given url out of the cache, and compute and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * cache them if they're not there.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    private void parseSpecs(URL url) throws MalformedURLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        String spec = url.getFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        int separator = spec.indexOf("!/");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
         * REMIND: we don't handle nested JAR URLs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        if (separator == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            throw new MalformedURLException("no !/ found in url spec:" + spec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        jarFileURL = new URL(spec.substring(0, separator++));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        entryName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        /* if ! is the last letter of the innerURL, entryName is null */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        if (++separator != spec.length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            entryName = spec.substring(separator, spec.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            entryName = ParseUtil.decode (entryName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * Returns the URL for the Jar file for this connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * @return the URL for the Jar file for this connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    public URL getJarFileURL() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        return jarFileURL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * Return the entry name for this connection. This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * returns null if the JAR file URL corresponding to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * connection points to a JAR file and not a JAR file entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @return the entry name for this connection, if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    public String getEntryName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        return entryName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * Return the JAR file for this connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * @return the JAR file for this connection. If the connection is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * a connection to an entry of a JAR file, the JAR file object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * @exception IOException if an IOException occurs while trying to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * connect to the JAR file for this connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @see #connect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    public abstract JarFile getJarFile() throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * Returns the Manifest for this connection, or null if none.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @return the manifest object corresponding to the JAR file object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * for this connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @exception IOException if getting the JAR file for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * connection causes an IOException to be trown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @see #getJarFile
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    public Manifest getManifest() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        return getJarFile().getManifest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * Return the JAR entry object for this connection, if any. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * method returns null if the JAR file URL corresponding to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * connection points to a JAR file and not a JAR file entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @return the JAR entry object for this connection, or null if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * the JAR URL for this connection points to a JAR file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * @exception IOException if getting the JAR file for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * connection causes an IOException to be trown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @see #getJarFile
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * @see #getJarEntry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    public JarEntry getJarEntry() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        return getJarFile().getJarEntry(entryName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * Return the Attributes object for this connection if the URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * for it points to a JAR file entry, null otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * @return the Attributes object for this connection if the URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * for it points to a JAR file entry, null otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * @exception IOException if getting the JAR entry causes an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * IOException to be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @see #getJarEntry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    public Attributes getAttributes() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        JarEntry e = getJarEntry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        return e != null ? e.getAttributes() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * Returns the main Attributes for the JAR file for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * @return the main Attributes for the JAR file for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @exception IOException if getting the manifest causes an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * IOException to be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @see #getJarFile
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * @see #getManifest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    public Attributes getMainAttributes() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        Manifest man = getManifest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        return man != null ? man.getMainAttributes() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * Return the Certificate object for this connection if the URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * for it points to a JAR file entry, null otherwise. This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * can only be called once
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * the connection has been completely verified by reading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * from the input stream until the end of the stream has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * reached. Otherwise, this method will return <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * @return the Certificate object for this connection if the URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * for it points to a JAR file entry, null otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * @exception IOException if getting the JAR entry causes an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * IOException to be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * @see #getJarEntry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    public java.security.cert.Certificate[] getCertificates()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
         throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        JarEntry e = getJarEntry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        return e != null ? e.getCertificates() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
}