8152277: Move URLClassPath.pathToURLs(String) to RegistryImpl
Reviewed-by: alanb
This commit is contained in:
parent
b40e890e78
commit
ef944b06b4
@ -401,36 +401,6 @@ public class URLClassPath {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert class path specification into an array of file URLs.
|
||||
*
|
||||
* The path of the file is encoded before conversion into URL
|
||||
* form so that reserved characters can safely appear in the path.
|
||||
*/
|
||||
public static URL[] pathToURLs(String path) {
|
||||
StringTokenizer st = new StringTokenizer(path, File.pathSeparator);
|
||||
URL[] urls = new URL[st.countTokens()];
|
||||
int count = 0;
|
||||
while (st.hasMoreTokens()) {
|
||||
File f = new File(st.nextToken());
|
||||
try {
|
||||
f = new File(f.getCanonicalPath());
|
||||
} catch (IOException x) {
|
||||
// use the non-canonicalized filename
|
||||
}
|
||||
try {
|
||||
urls[count++] = ParseUtil.fileToEncodedURL(f);
|
||||
} catch (IOException x) { }
|
||||
}
|
||||
|
||||
if (urls.length != count) {
|
||||
URL[] tmp = new URL[count];
|
||||
System.arraycopy(urls, 0, tmp, 0, count);
|
||||
urls = tmp;
|
||||
}
|
||||
return urls;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check whether the resource URL should be returned.
|
||||
* Return null on security check failure.
|
||||
|
@ -25,10 +25,15 @@
|
||||
|
||||
package sun.rmi.registry;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
import java.io.File;
|
||||
import java.io.FilePermission;
|
||||
import java.io.IOException;
|
||||
import java.net.*;
|
||||
@ -332,6 +337,30 @@ public class RegistryImpl extends java.rmi.server.RemoteServer
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert class path specification into an array of file URLs.
|
||||
*
|
||||
* The path of the file is converted to a URI then into URL
|
||||
* form so that reserved characters can safely appear in the path.
|
||||
*/
|
||||
private static URL[] pathToURLs(String path) {
|
||||
List<URL> paths = new ArrayList<>();
|
||||
for (String entry: path.split(File.pathSeparator)) {
|
||||
Path p = Paths.get(entry);
|
||||
try {
|
||||
p = p.toRealPath();
|
||||
} catch (IOException x) {
|
||||
p = p.toAbsolutePath();
|
||||
}
|
||||
try {
|
||||
paths.add(p.toUri().toURL());
|
||||
} catch (MalformedURLException e) {
|
||||
//ignore / skip entry
|
||||
}
|
||||
}
|
||||
return paths.toArray(new URL[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Main program to start a registry. <br>
|
||||
* The port number can be specified on the command line.
|
||||
@ -362,7 +391,7 @@ public class RegistryImpl extends java.rmi.server.RemoteServer
|
||||
if (envcp == null) {
|
||||
envcp = "."; // preserve old default behavior
|
||||
}
|
||||
URL[] urls = sun.misc.URLClassPath.pathToURLs(envcp);
|
||||
URL[] urls = pathToURLs(envcp);
|
||||
ClassLoader cl = new URLClassLoader(urls);
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user