jdk/src/java.base/share/classes/sun/net/www/protocol/jar/URLJarFile.java
author sdrach
Mon, 15 Feb 2016 17:47:53 -0800
changeset 36129 332b49163fc9
parent 34943 52923a144ff6
child 39646 2bf99fe5023b
permissions -rw-r--r--
8132734: JDK 9 runtime changes to support multi-release jar files Summary: JEP 238 Multi-Release JAR Files runtime support Reviewed-by: alanb, psandoz, sherman
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
34943
52923a144ff6 8146567: Remove dead code finalizer methods
rriggs
parents: 29986
diff changeset
     2
 * Copyright (c) 2001, 2016, 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 {
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34943
diff changeset
    68
        if (isFileURL(url)) {
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34943
diff changeset
    69
            Release version = "runtime".equals(url.getRef()) ? Release.RUNTIME : Release.BASE;
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34943
diff changeset
    70
            return new URLJarFile(url, closeController, version);
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34943
diff changeset
    71
        } else {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            return retrieve(url, closeController);
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
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * Changed modifier from private to public in order to be able
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * to instantiate URLJarFile from sun.plugin package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    public URLJarFile(File file) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        this(file, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * Changed modifier from private to public in order to be able
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * to instantiate URLJarFile from sun.plugin package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public URLJarFile(File file, URLJarFileCloseController closeController) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        super(file, true, ZipFile.OPEN_READ | ZipFile.OPEN_DELETE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        this.closeController = closeController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34943
diff changeset
    93
    private URLJarFile(File file, URLJarFileCloseController closeController, Release version) throws IOException {
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34943
diff changeset
    94
        super(file, true, ZipFile.OPEN_READ | ZipFile.OPEN_DELETE, version);
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34943
diff changeset
    95
        this.closeController = closeController;
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34943
diff changeset
    96
    }
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34943
diff changeset
    97
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34943
diff changeset
    98
    private URLJarFile(URL url, URLJarFileCloseController closeController, Release version) throws IOException {
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34943
diff changeset
    99
        super(new File(ParseUtil.decode(url.getFile())), true, ZipFile.OPEN_READ, version);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        this.closeController = closeController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    private static boolean isFileURL(URL url) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        if (url.getProtocol().equalsIgnoreCase("file")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
             * Consider this a 'file' only if it's a LOCAL file, because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
             * 'file:' URLs can be accessible through ftp.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            String host = url.getHost();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            if (host == null || host.equals("") || host.equals("~") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                host.equalsIgnoreCase("localhost"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * Returns the <code>ZipEntry</code> for the given entry name or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * <code>null</code> if not found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @param name the JAR file entry name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @return the <code>ZipEntry</code> for the given entry name or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *         <code>null</code> if not found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @see java.util.zip.ZipEntry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public ZipEntry getEntry(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        ZipEntry ze = super.getEntry(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        if (ze != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            if (ze instanceof JarEntry)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                return new URLJarFileEntry((JarEntry)ze);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                throw new InternalError(super.getClass() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                                        " returned unexpected entry type " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                                        ze.getClass());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    public Manifest getManifest() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        if (!isSuperMan()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        Manifest man = new Manifest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        Attributes attr = man.getMainAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        attr.putAll((Map)superAttr.clone());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        // now deep copy the manifest entries
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        if (superEntries != null) {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   151
            Map<String, Attributes> entries = man.getEntries();
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   152
            for (String key : superEntries.keySet()) {
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   153
                Attributes at = superEntries.get(key);
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   154
                entries.put(key, (Attributes) at.clone());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        return man;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    /* If close controller is set the notify the controller about the pending close */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    public void close() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        if (closeController != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                closeController.close(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        super.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    // optimal side-effects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    private synchronized boolean isSuperMan() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        if (superMan == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            superMan = super.getManifest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        if (superMan != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            superAttr = superMan.getMainAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            superEntries = superMan.getEntries();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            return false;
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
     * Given a URL, retrieves a JAR file, caches it to disk, and creates a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * cached JAR file object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     private static JarFile retrieve(final URL url, final URLJarFileCloseController closeController) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
         * See if interface is set, then call retrieve function of the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
         * that implements URLJarFileCallBack interface (sun.plugin - to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
         * handle the cache failure for JARJAR file.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        if (callback != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            return callback.retrieve(url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            JarFile result = null;
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34943
diff changeset
   203
            Release version = "runtime".equals(url.getRef()) ? Release.RUNTIME : Release.BASE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            /* get the stream before asserting privileges */
8400
b52368af8137 7018392: update URLJarFile.java to use try-with-resources
smarks
parents: 5506
diff changeset
   206
            try (final InputStream in = url.openConnection().getInputStream()) {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   207
                result = AccessController.doPrivileged(
29986
97167d851fc4 8078467: Update core libraries to use diamond with anonymous classes
darcy
parents: 25859
diff changeset
   208
                    new PrivilegedExceptionAction<>() {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   209
                        public JarFile run() throws IOException {
8400
b52368af8137 7018392: update URLJarFile.java to use try-with-resources
smarks
parents: 5506
diff changeset
   210
                            Path tmpFile = Files.createTempFile("jar_cache", null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                            try {
8400
b52368af8137 7018392: update URLJarFile.java to use try-with-resources
smarks
parents: 5506
diff changeset
   212
                                Files.copy(in, tmpFile, StandardCopyOption.REPLACE_EXISTING);
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34943
diff changeset
   213
                                JarFile jarFile = new URLJarFile(tmpFile.toFile(), closeController, version);
8400
b52368af8137 7018392: update URLJarFile.java to use try-with-resources
smarks
parents: 5506
diff changeset
   214
                                tmpFile.toFile().deleteOnExit();
b52368af8137 7018392: update URLJarFile.java to use try-with-resources
smarks
parents: 5506
diff changeset
   215
                                return jarFile;
b52368af8137 7018392: update URLJarFile.java to use try-with-resources
smarks
parents: 5506
diff changeset
   216
                            } catch (Throwable thr) {
b52368af8137 7018392: update URLJarFile.java to use try-with-resources
smarks
parents: 5506
diff changeset
   217
                                try {
b52368af8137 7018392: update URLJarFile.java to use try-with-resources
smarks
parents: 5506
diff changeset
   218
                                    Files.delete(tmpFile);
b52368af8137 7018392: update URLJarFile.java to use try-with-resources
smarks
parents: 5506
diff changeset
   219
                                } catch (IOException ioe) {
b52368af8137 7018392: update URLJarFile.java to use try-with-resources
smarks
parents: 5506
diff changeset
   220
                                    thr.addSuppressed(ioe);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                                }
8400
b52368af8137 7018392: update URLJarFile.java to use try-with-resources
smarks
parents: 5506
diff changeset
   222
                                throw thr;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                    });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            } catch (PrivilegedActionException pae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                throw (IOException) pae.getException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            return result;
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
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * Set the call back interface to call retrive function in sun.plugin
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * package if plugin is running.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    public static void setCallBack(URLJarFileCallBack cb)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        callback = cb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    private class URLJarFileEntry extends JarEntry {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        private JarEntry je;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        URLJarFileEntry(JarEntry je) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            super(je);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            this.je=je;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        public Attributes getAttributes() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            if (URLJarFile.this.isSuperMan()) {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   254
                Map<String, Attributes> e = URLJarFile.this.superEntries;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                if (e != null) {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   256
                    Attributes a = e.get(getName());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                    if (a != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                        return  (Attributes)a.clone();
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 null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        public java.security.cert.Certificate[] getCertificates() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            Certificate[] certs = je.getCertificates();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            return certs == null? null: certs.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
        public CodeSigner[] getCodeSigners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            CodeSigner[] csg = je.getCodeSigners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            return csg == null? null: csg.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    public interface URLJarFileCloseController {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        public void close(JarFile jarFile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
}