jdk/src/share/classes/sun/net/www/protocol/jar/URLJarFile.java
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 8400 b52368af8137
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 8400
diff changeset
     2
 * Copyright (c) 2001, 2011, 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: 715
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: 715
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: 715
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
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 sun.net.www.protocol.jar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.net.*;
8400
b52368af8137 7018392: update URLJarFile.java to use try-with-resources
smarks
parents: 5506
diff changeset
    30
import java.nio.file.Files;
b52368af8137 7018392: update URLJarFile.java to use try-with-resources
smarks
parents: 5506
diff changeset
    31
import java.nio.file.Path;
b52368af8137 7018392: update URLJarFile.java to use try-with-resources
smarks
parents: 5506
diff changeset
    32
import java.nio.file.StandardCopyOption;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.jar.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.zip.ZipFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.zip.ZipEntry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.security.CodeSigner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.security.cert.Certificate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.security.PrivilegedExceptionAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.security.PrivilegedActionException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import sun.net.www.ParseUtil;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
/* URL jar file is a common JarFile subtype used for JarURLConnection */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
public class URLJarFile extends JarFile {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * Interface to be able to call retrieve() in plugin if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * this variable is set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private static URLJarFileCallBack callback = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    /* Controller of the Jar File's closing */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private URLJarFileCloseController closeController = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private static int BUF_SIZE = 2048;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private Manifest superMan;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private Attributes superAttr;
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
    61
    private Map<String, Attributes> superEntries;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    static JarFile getJarFile(URL url) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        return getJarFile(url, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    static JarFile getJarFile(URL url, URLJarFileCloseController closeController) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        if (isFileURL(url))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            return new URLJarFile(url, closeController);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            return retrieve(url, closeController);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * Changed modifier from private to public in order to be able
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * to instantiate URLJarFile from sun.plugin package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    public URLJarFile(File file) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        this(file, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * Changed modifier from private to public in order to be able
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * to instantiate URLJarFile from sun.plugin package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public URLJarFile(File file, URLJarFileCloseController closeController) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        super(file, true, ZipFile.OPEN_READ | ZipFile.OPEN_DELETE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        this.closeController = closeController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    private URLJarFile(URL url, URLJarFileCloseController closeController) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        super(ParseUtil.decode(url.getFile()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        this.closeController = closeController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private static boolean isFileURL(URL url) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        if (url.getProtocol().equalsIgnoreCase("file")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
             * Consider this a 'file' only if it's a LOCAL file, because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
             * 'file:' URLs can be accessible through ftp.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            String host = url.getHost();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            if (host == null || host.equals("") || host.equals("~") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                host.equalsIgnoreCase("localhost"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * close the jar file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    protected void finalize() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * Returns the <code>ZipEntry</code> for the given entry name or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * <code>null</code> if not found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @param name the JAR file entry name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @return the <code>ZipEntry</code> for the given entry name or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     *         <code>null</code> if not found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @see java.util.zip.ZipEntry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    public ZipEntry getEntry(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        ZipEntry ze = super.getEntry(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        if (ze != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            if (ze instanceof JarEntry)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                return new URLJarFileEntry((JarEntry)ze);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                throw new InternalError(super.getClass() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                                        " returned unexpected entry type " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                                        ze.getClass());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    public Manifest getManifest() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        if (!isSuperMan()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        Manifest man = new Manifest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        Attributes attr = man.getMainAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        attr.putAll((Map)superAttr.clone());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        // now deep copy the manifest entries
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        if (superEntries != null) {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   152
            Map<String, Attributes> entries = man.getEntries();
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   153
            for (String key : superEntries.keySet()) {
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   154
                Attributes at = superEntries.get(key);
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   155
                entries.put(key, (Attributes) at.clone());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        return man;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    /* If close controller is set the notify the controller about the pending close */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    public void close() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        if (closeController != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                closeController.close(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        super.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    // optimal side-effects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    private synchronized boolean isSuperMan() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        if (superMan == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            superMan = super.getManifest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        if (superMan != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            superAttr = superMan.getMainAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            superEntries = superMan.getEntries();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            return false;
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
     * Given a URL, retrieves a JAR file, caches it to disk, and creates a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * cached JAR file object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    private static JarFile retrieve(final URL url) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        return retrieve(url, null);
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
     * Given a URL, retrieves a JAR file, caches it to disk, and creates a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * cached JAR file object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     private static JarFile retrieve(final URL url, final URLJarFileCloseController closeController) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
         * See if interface is set, then call retrieve function of the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
         * that implements URLJarFileCallBack interface (sun.plugin - to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
         * handle the cache failure for JARJAR file.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        if (callback != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            return callback.retrieve(url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            JarFile result = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            /* get the stream before asserting privileges */
8400
b52368af8137 7018392: update URLJarFile.java to use try-with-resources
smarks
parents: 5506
diff changeset
   214
            try (final InputStream in = url.openConnection().getInputStream()) {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   215
                result = AccessController.doPrivileged(
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   216
                    new PrivilegedExceptionAction<JarFile>() {
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   217
                        public JarFile run() throws IOException {
8400
b52368af8137 7018392: update URLJarFile.java to use try-with-resources
smarks
parents: 5506
diff changeset
   218
                            Path tmpFile = Files.createTempFile("jar_cache", null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                            try {
8400
b52368af8137 7018392: update URLJarFile.java to use try-with-resources
smarks
parents: 5506
diff changeset
   220
                                Files.copy(in, tmpFile, StandardCopyOption.REPLACE_EXISTING);
b52368af8137 7018392: update URLJarFile.java to use try-with-resources
smarks
parents: 5506
diff changeset
   221
                                JarFile jarFile = new URLJarFile(tmpFile.toFile(), closeController);
b52368af8137 7018392: update URLJarFile.java to use try-with-resources
smarks
parents: 5506
diff changeset
   222
                                tmpFile.toFile().deleteOnExit();
b52368af8137 7018392: update URLJarFile.java to use try-with-resources
smarks
parents: 5506
diff changeset
   223
                                return jarFile;
b52368af8137 7018392: update URLJarFile.java to use try-with-resources
smarks
parents: 5506
diff changeset
   224
                            } catch (Throwable thr) {
b52368af8137 7018392: update URLJarFile.java to use try-with-resources
smarks
parents: 5506
diff changeset
   225
                                try {
b52368af8137 7018392: update URLJarFile.java to use try-with-resources
smarks
parents: 5506
diff changeset
   226
                                    Files.delete(tmpFile);
b52368af8137 7018392: update URLJarFile.java to use try-with-resources
smarks
parents: 5506
diff changeset
   227
                                } catch (IOException ioe) {
b52368af8137 7018392: update URLJarFile.java to use try-with-resources
smarks
parents: 5506
diff changeset
   228
                                    thr.addSuppressed(ioe);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                                }
8400
b52368af8137 7018392: update URLJarFile.java to use try-with-resources
smarks
parents: 5506
diff changeset
   230
                                throw thr;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                    });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            } catch (PrivilegedActionException pae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                throw (IOException) pae.getException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        }
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
     * Set the call back interface to call retrive function in sun.plugin
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * package if plugin is running.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    public static void setCallBack(URLJarFileCallBack cb)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        callback = cb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    private class URLJarFileEntry extends JarEntry {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        private JarEntry je;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        URLJarFileEntry(JarEntry je) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            super(je);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            this.je=je;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        public Attributes getAttributes() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            if (URLJarFile.this.isSuperMan()) {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   262
                Map<String, Attributes> e = URLJarFile.this.superEntries;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                if (e != null) {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   264
                    Attributes a = e.get(getName());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                    if (a != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                        return  (Attributes)a.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        public java.security.cert.Certificate[] getCertificates() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            Certificate[] certs = je.getCertificates();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            return certs == null? null: certs.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        public CodeSigner[] getCodeSigners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            CodeSigner[] csg = je.getCodeSigners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            return csg == null? null: csg.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    public interface URLJarFileCloseController {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        public void close(JarFile jarFile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
}