mirror of
https://github.com/openjdk/jdk.git
synced 2026-02-14 20:35:09 +00:00
Merge
This commit is contained in:
commit
658feaa3e4
@ -41,6 +41,7 @@ FILES_java = \
|
||||
sun/net/NetProperties.java \
|
||||
sun/net/NetHooks.java \
|
||||
sun/net/util/IPAddressUtil.java \
|
||||
sun/net/util/URLUtil.java \
|
||||
sun/net/dns/ResolverConfiguration.java \
|
||||
sun/net/dns/ResolverConfigurationImpl.java \
|
||||
sun/net/ftp/FtpClient.java \
|
||||
|
||||
@ -51,6 +51,7 @@ import java.security.PrivilegedAction;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
import java.security.cert.Certificate;
|
||||
import sun.misc.FileURLMapper;
|
||||
import sun.net.util.URLUtil;
|
||||
|
||||
/**
|
||||
* This class is used to maintain a search path of URLs for loading classes
|
||||
@ -80,7 +81,7 @@ public class URLClassPath {
|
||||
ArrayList<Loader> loaders = new ArrayList<Loader>();
|
||||
|
||||
/* Map of each URL opened to its corresponding Loader */
|
||||
HashMap<URL, Loader> lmap = new HashMap<URL, Loader>();
|
||||
HashMap<String, Loader> lmap = new HashMap<String, Loader>();
|
||||
|
||||
/* The jar protocol handler to use when creating new URLs */
|
||||
private URLStreamHandler jarHandler;
|
||||
@ -317,7 +318,8 @@ public class URLClassPath {
|
||||
// Skip this URL if it already has a Loader. (Loader
|
||||
// may be null in the case where URL has not been opened
|
||||
// but is referenced by a JAR index.)
|
||||
if (lmap.containsKey(url)) {
|
||||
String urlNoFragString = URLUtil.urlNoFragString(url);
|
||||
if (lmap.containsKey(urlNoFragString)) {
|
||||
continue;
|
||||
}
|
||||
// Otherwise, create a new Loader for the URL.
|
||||
@ -336,7 +338,7 @@ public class URLClassPath {
|
||||
}
|
||||
// Finally, add the Loader to the search path.
|
||||
loaders.add(loader);
|
||||
lmap.put(url, loader);
|
||||
lmap.put(urlNoFragString, loader);
|
||||
}
|
||||
return loaders.get(index);
|
||||
}
|
||||
@ -576,7 +578,7 @@ public class URLClassPath {
|
||||
private JarIndex index;
|
||||
private MetaIndex metaIndex;
|
||||
private URLStreamHandler handler;
|
||||
private HashMap<URL, Loader> lmap;
|
||||
private HashMap<String, Loader> lmap;
|
||||
private boolean closed = false;
|
||||
|
||||
/*
|
||||
@ -584,7 +586,7 @@ public class URLClassPath {
|
||||
* a JAR file.
|
||||
*/
|
||||
JarLoader(URL url, URLStreamHandler jarHandler,
|
||||
HashMap<URL, Loader> loaderMap)
|
||||
HashMap<String, Loader> loaderMap)
|
||||
throws IOException
|
||||
{
|
||||
super(new URL("jar", "", -1, url + "!/", jarHandler));
|
||||
@ -663,8 +665,9 @@ public class URLClassPath {
|
||||
try {
|
||||
URL jarURL = new URL(csu, jarfiles[i]);
|
||||
// If a non-null loader already exists, leave it alone.
|
||||
if (!lmap.containsKey(jarURL)) {
|
||||
lmap.put(jarURL, null);
|
||||
String urlNoFragString = URLUtil.urlNoFragString(jarURL);
|
||||
if (!lmap.containsKey(urlNoFragString)) {
|
||||
lmap.put(urlNoFragString, null);
|
||||
}
|
||||
} catch (MalformedURLException e) {
|
||||
continue;
|
||||
@ -806,7 +809,7 @@ public class URLClassPath {
|
||||
if (index == null)
|
||||
return null;
|
||||
|
||||
HashSet<URL> visited = new HashSet<URL>();
|
||||
HashSet<String> visited = new HashSet<String>();
|
||||
return getResource(name, check, visited);
|
||||
}
|
||||
|
||||
@ -818,7 +821,7 @@ public class URLClassPath {
|
||||
* non-existent resource
|
||||
*/
|
||||
Resource getResource(final String name, boolean check,
|
||||
Set<URL> visited) {
|
||||
Set<String> visited) {
|
||||
|
||||
Resource res;
|
||||
Object[] jarFiles;
|
||||
@ -843,7 +846,8 @@ public class URLClassPath {
|
||||
|
||||
try{
|
||||
url = new URL(csu, jarName);
|
||||
if ((newLoader = (JarLoader)lmap.get(url)) == null) {
|
||||
String urlNoFragString = URLUtil.urlNoFragString(url);
|
||||
if ((newLoader = (JarLoader)lmap.get(urlNoFragString)) == null) {
|
||||
/* no loader has been set up for this jar file
|
||||
* before
|
||||
*/
|
||||
@ -867,7 +871,7 @@ public class URLClassPath {
|
||||
}
|
||||
|
||||
/* put it in the global hashtable */
|
||||
lmap.put(url, newLoader);
|
||||
lmap.put(urlNoFragString, newLoader);
|
||||
}
|
||||
} catch (java.security.PrivilegedActionException pae) {
|
||||
continue;
|
||||
@ -879,7 +883,7 @@ public class URLClassPath {
|
||||
/* Note that the addition of the url to the list of visited
|
||||
* jars incorporates a check for presence in the hashmap
|
||||
*/
|
||||
boolean visitedURL = !visited.add(url);
|
||||
boolean visitedURL = !visited.add(URLUtil.urlNoFragString(url));
|
||||
if (!visitedURL) {
|
||||
try {
|
||||
newLoader.ensureOpen();
|
||||
|
||||
80
jdk/src/share/classes/sun/net/util/URLUtil.java
Normal file
80
jdk/src/share/classes/sun/net/util/URLUtil.java
Normal file
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Sun designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Sun in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||
* have any questions.
|
||||
*/
|
||||
|
||||
package sun.net.util;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* URL Utility class.
|
||||
*/
|
||||
public class URLUtil {
|
||||
/**
|
||||
* Returns a string form of the url suitable for use as a key in HashMap/Sets.
|
||||
*
|
||||
* The string form should be behave in the same manner as the URL when
|
||||
* compared for equality in a HashMap/Set, except that no nameservice
|
||||
* lookup is done on the hostname (only string comparison), and the fragment
|
||||
* is not considered.
|
||||
*
|
||||
* @see java.net.URLStreamHandler.sameFile(java.net.URL)
|
||||
*/
|
||||
public static String urlNoFragString(URL url) {
|
||||
StringBuilder strForm = new StringBuilder();
|
||||
|
||||
String protocol = url.getProtocol();
|
||||
if (protocol != null) {
|
||||
/* protocol is compared case-insensitive, so convert to lowercase */
|
||||
protocol = protocol.toLowerCase();
|
||||
strForm.append(protocol);
|
||||
strForm.append("://");
|
||||
}
|
||||
|
||||
String host = url.getHost();
|
||||
if (host != null) {
|
||||
/* host is compared case-insensitive, so convert to lowercase */
|
||||
host = host.toLowerCase();
|
||||
strForm.append(host);
|
||||
|
||||
int port = url.getPort();
|
||||
if (port == -1) {
|
||||
/* if no port is specificed then use the protocols
|
||||
* default, if there is one */
|
||||
port = url.getDefaultPort();
|
||||
}
|
||||
if (port != -1) {
|
||||
strForm.append(":").append(port);
|
||||
}
|
||||
}
|
||||
|
||||
String file = url.getFile();
|
||||
if (file != null) {
|
||||
strForm.append(file);
|
||||
}
|
||||
|
||||
return strForm.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,12 +25,14 @@
|
||||
|
||||
package sun.net.www.protocol.jar;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
import java.util.jar.*;
|
||||
import java.util.zip.ZipFile;
|
||||
import java.io.IOException;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.HashMap;
|
||||
import java.util.jar.JarFile;
|
||||
import java.security.Permission;
|
||||
import sun.net.util.URLUtil;
|
||||
|
||||
/* A factory for cached JAR file. This class is used to both retrieve
|
||||
* and cache Jar files.
|
||||
@ -41,13 +43,13 @@ import java.security.Permission;
|
||||
class JarFileFactory implements URLJarFile.URLJarFileCloseController {
|
||||
|
||||
/* the url to file cache */
|
||||
private static HashMap fileCache = new HashMap();
|
||||
private static HashMap<String, JarFile> fileCache = new HashMap<String, JarFile>();
|
||||
|
||||
/* the file to url cache */
|
||||
private static HashMap urlCache = new HashMap();
|
||||
private static HashMap<JarFile, URL> urlCache = new HashMap<JarFile, URL>();
|
||||
|
||||
URLConnection getConnection(JarFile jarFile) throws IOException {
|
||||
URL u = (URL)urlCache.get(jarFile);
|
||||
URL u = urlCache.get(jarFile);
|
||||
if (u != null)
|
||||
return u.openConnection();
|
||||
|
||||
@ -72,7 +74,7 @@ class JarFileFactory implements URLJarFile.URLJarFileCloseController {
|
||||
synchronized (this) {
|
||||
result = getCachedJarFile(url);
|
||||
if (result == null) {
|
||||
fileCache.put(url, local_result);
|
||||
fileCache.put(URLUtil.urlNoFragString(url), local_result);
|
||||
urlCache.put(local_result, url);
|
||||
result = local_result;
|
||||
} else {
|
||||
@ -97,15 +99,15 @@ class JarFileFactory implements URLJarFile.URLJarFileCloseController {
|
||||
* remove the JarFile from the cache
|
||||
*/
|
||||
public void close(JarFile jarFile) {
|
||||
URL urlRemoved = (URL) urlCache.remove(jarFile);
|
||||
URL urlRemoved = urlCache.remove(jarFile);
|
||||
if( urlRemoved != null) {
|
||||
fileCache.remove(urlRemoved);
|
||||
fileCache.remove(URLUtil.urlNoFragString(urlRemoved));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private JarFile getCachedJarFile(URL url) {
|
||||
JarFile result = (JarFile)fileCache.get(url);
|
||||
JarFile result = fileCache.get(URLUtil.urlNoFragString(url));
|
||||
|
||||
/* if the JAR file is cached, the permission will always be there */
|
||||
if (result != null) {
|
||||
|
||||
@ -25,12 +25,14 @@
|
||||
|
||||
package sun.net.www.protocol.jar;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
import java.util.jar.*;
|
||||
import java.util.zip.ZipFile;
|
||||
import java.io.IOException;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.HashMap;
|
||||
import java.util.jar.JarFile;
|
||||
import java.security.Permission;
|
||||
import sun.net.util.URLUtil;
|
||||
|
||||
/* A factory for cached JAR file. This class is used to both retrieve
|
||||
* and cache Jar files.
|
||||
@ -41,13 +43,13 @@ import java.security.Permission;
|
||||
class JarFileFactory implements URLJarFile.URLJarFileCloseController {
|
||||
|
||||
/* the url to file cache */
|
||||
private static HashMap fileCache = new HashMap();
|
||||
private static HashMap<String, JarFile> fileCache = new HashMap<String, JarFile>();
|
||||
|
||||
/* the file to url cache */
|
||||
private static HashMap urlCache = new HashMap();
|
||||
private static HashMap<JarFile, URL> urlCache = new HashMap<JarFile, URL>();
|
||||
|
||||
URLConnection getConnection(JarFile jarFile) throws IOException {
|
||||
URL u = (URL)urlCache.get(jarFile);
|
||||
URL u = urlCache.get(jarFile);
|
||||
if (u != null)
|
||||
return u.openConnection();
|
||||
|
||||
@ -82,7 +84,7 @@ class JarFileFactory implements URLJarFile.URLJarFileCloseController {
|
||||
synchronized (this) {
|
||||
result = getCachedJarFile(url);
|
||||
if (result == null) {
|
||||
fileCache.put(url, local_result);
|
||||
fileCache.put(URLUtil.urlNoFragString(url), local_result);
|
||||
urlCache.put(local_result, url);
|
||||
result = local_result;
|
||||
} else {
|
||||
@ -107,14 +109,14 @@ class JarFileFactory implements URLJarFile.URLJarFileCloseController {
|
||||
* remove the JarFile from the cache
|
||||
*/
|
||||
public void close(JarFile jarFile) {
|
||||
URL urlRemoved = (URL) urlCache.remove(jarFile);
|
||||
URL urlRemoved = urlCache.remove(jarFile);
|
||||
if( urlRemoved != null) {
|
||||
fileCache.remove(urlRemoved);
|
||||
fileCache.remove(URLUtil.urlNoFragString(urlRemoved));
|
||||
}
|
||||
}
|
||||
|
||||
private JarFile getCachedJarFile(URL url) {
|
||||
JarFile result = (JarFile)fileCache.get(url);
|
||||
JarFile result = fileCache.get(URLUtil.urlNoFragString(url));
|
||||
|
||||
/* if the JAR file is cached, the permission will always be there */
|
||||
if (result != null) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user