提交 27f90c20 编写于 作者: C chegar

6826801: JarFileFactory should not use HashMap<URL>

Summary: Replace URL with a String representation.
Reviewed-by: michaelm, jccollet
上级 a93246c9
...@@ -25,12 +25,14 @@ ...@@ -25,12 +25,14 @@
package sun.net.www.protocol.jar; package sun.net.www.protocol.jar;
import java.io.*; import java.io.IOException;
import java.net.*; import java.io.FileNotFoundException;
import java.util.*; import java.net.URL;
import java.util.jar.*; import java.net.URLConnection;
import java.util.zip.ZipFile; import java.util.HashMap;
import java.util.jar.JarFile;
import java.security.Permission; import java.security.Permission;
import sun.net.util.URLUtil;
/* A factory for cached JAR file. This class is used to both retrieve /* A factory for cached JAR file. This class is used to both retrieve
* and cache Jar files. * and cache Jar files.
...@@ -41,13 +43,13 @@ import java.security.Permission; ...@@ -41,13 +43,13 @@ import java.security.Permission;
class JarFileFactory implements URLJarFile.URLJarFileCloseController { class JarFileFactory implements URLJarFile.URLJarFileCloseController {
/* the url to file cache */ /* 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 */ /* 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 { URLConnection getConnection(JarFile jarFile) throws IOException {
URL u = (URL)urlCache.get(jarFile); URL u = urlCache.get(jarFile);
if (u != null) if (u != null)
return u.openConnection(); return u.openConnection();
...@@ -72,7 +74,7 @@ class JarFileFactory implements URLJarFile.URLJarFileCloseController { ...@@ -72,7 +74,7 @@ class JarFileFactory implements URLJarFile.URLJarFileCloseController {
synchronized (this) { synchronized (this) {
result = getCachedJarFile(url); result = getCachedJarFile(url);
if (result == null) { if (result == null) {
fileCache.put(url, local_result); fileCache.put(URLUtil.urlNoFragString(url), local_result);
urlCache.put(local_result, url); urlCache.put(local_result, url);
result = local_result; result = local_result;
} else { } else {
...@@ -97,15 +99,15 @@ class JarFileFactory implements URLJarFile.URLJarFileCloseController { ...@@ -97,15 +99,15 @@ class JarFileFactory implements URLJarFile.URLJarFileCloseController {
* remove the JarFile from the cache * remove the JarFile from the cache
*/ */
public void close(JarFile jarFile) { public void close(JarFile jarFile) {
URL urlRemoved = (URL) urlCache.remove(jarFile); URL urlRemoved = urlCache.remove(jarFile);
if( urlRemoved != null) { if( urlRemoved != null) {
fileCache.remove(urlRemoved); fileCache.remove(URLUtil.urlNoFragString(urlRemoved));
} }
} }
private JarFile getCachedJarFile(URL url) { 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 the JAR file is cached, the permission will always be there */
if (result != null) { if (result != null) {
......
...@@ -25,12 +25,14 @@ ...@@ -25,12 +25,14 @@
package sun.net.www.protocol.jar; package sun.net.www.protocol.jar;
import java.io.*; import java.io.IOException;
import java.net.*; import java.io.FileNotFoundException;
import java.util.*; import java.net.URL;
import java.util.jar.*; import java.net.URLConnection;
import java.util.zip.ZipFile; import java.util.HashMap;
import java.util.jar.JarFile;
import java.security.Permission; import java.security.Permission;
import sun.net.util.URLUtil;
/* A factory for cached JAR file. This class is used to both retrieve /* A factory for cached JAR file. This class is used to both retrieve
* and cache Jar files. * and cache Jar files.
...@@ -41,13 +43,13 @@ import java.security.Permission; ...@@ -41,13 +43,13 @@ import java.security.Permission;
class JarFileFactory implements URLJarFile.URLJarFileCloseController { class JarFileFactory implements URLJarFile.URLJarFileCloseController {
/* the url to file cache */ /* 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 */ /* 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 { URLConnection getConnection(JarFile jarFile) throws IOException {
URL u = (URL)urlCache.get(jarFile); URL u = urlCache.get(jarFile);
if (u != null) if (u != null)
return u.openConnection(); return u.openConnection();
...@@ -82,7 +84,7 @@ class JarFileFactory implements URLJarFile.URLJarFileCloseController { ...@@ -82,7 +84,7 @@ class JarFileFactory implements URLJarFile.URLJarFileCloseController {
synchronized (this) { synchronized (this) {
result = getCachedJarFile(url); result = getCachedJarFile(url);
if (result == null) { if (result == null) {
fileCache.put(url, local_result); fileCache.put(URLUtil.urlNoFragString(url), local_result);
urlCache.put(local_result, url); urlCache.put(local_result, url);
result = local_result; result = local_result;
} else { } else {
...@@ -107,14 +109,14 @@ class JarFileFactory implements URLJarFile.URLJarFileCloseController { ...@@ -107,14 +109,14 @@ class JarFileFactory implements URLJarFile.URLJarFileCloseController {
* remove the JarFile from the cache * remove the JarFile from the cache
*/ */
public void close(JarFile jarFile) { public void close(JarFile jarFile) {
URL urlRemoved = (URL) urlCache.remove(jarFile); URL urlRemoved = urlCache.remove(jarFile);
if( urlRemoved != null) { if( urlRemoved != null) {
fileCache.remove(urlRemoved); fileCache.remove(URLUtil.urlNoFragString(urlRemoved));
} }
} }
private JarFile getCachedJarFile(URL url) { 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 the JAR file is cached, the permission will always be there */
if (result != null) { if (result != null) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册