| Method from sun.misc.URLClassPath Detail: |
public void addURL(URL url) {
synchronized (urls) {
if (url == null || path.contains(url))
return;
urls.add(0, url);
path.add(url);
}
}
Appends the specified URL to the search path of directory and JAR
file URLs from which to load classes and resources.
If the URL specified is null or is already in the list of
URLs, then invoking this method has no effect. |
static void check(URL url) throws IOException {
SecurityManager security = System.getSecurityManager();
if (security != null) {
URLConnection urlConnection = url.openConnection();
Permission perm = urlConnection.getPermission();
if (perm != null) {
try {
security.checkPermission(perm);
} catch (SecurityException se) {
// fallback to checkRead/checkConnect for pre 1.2
// security managers
if ((perm instanceof java.io.FilePermission) &&
perm.getActions().indexOf("read") != -1) {
security.checkRead(perm.getName());
} else if ((perm instanceof
java.net.SocketPermission) &&
perm.getActions().indexOf("connect") != -1) {
URL locUrl = url;
if (urlConnection instanceof JarURLConnection) {
locUrl = ((JarURLConnection)urlConnection).getJarFileURL();
}
security.checkConnect(locUrl.getHost(),
locUrl.getPort());
} else {
throw se;
}
}
}
}
}
|
public URL checkURL(URL url) {
try {
check(url);
} catch (Exception e) {
return null;
}
return url;
}
|
public URL findResource(String name,
boolean check) {
Loader loader;
for (int i = 0; (loader = getLoader(i)) != null; i++) {
URL url = loader.findResource(name, check);
if (url != null) {
return url;
}
}
return null;
}
Finds the resource with the specified name on the URL search path
or null if not found or security check fails. |
public Enumeration findResources(String name,
boolean check) {
return new Enumeration< URL >() {
private int index = 0;
private URL url = null;
private boolean next() {
if (url != null) {
return true;
} else {
Loader loader;
while ((loader = getLoader(index++)) != null) {
url = loader.findResource(name, check);
if (url != null) {
return true;
}
}
return false;
}
}
public boolean hasMoreElements() {
return next();
}
public URL nextElement() {
if (!next()) {
throw new NoSuchElementException();
}
URL u = url;
url = null;
return u;
}
};
}
Finds all resources on the URL search path with the given name.
Returns an enumeration of the URL objects. |
public Resource getResource(String name) {
return getResource(name, true);
}
|
public Resource getResource(String name,
boolean check) {
if (DEBUG) {
System.err.println("URLClassPath.getResource(\"" + name + "\")");
}
Loader loader;
for (int i = 0; (loader = getLoader(i)) != null; i++) {
Resource res = loader.getResource(name, check);
if (res != null) {
return res;
}
}
return null;
}
Finds the first Resource on the URL search path which has the specified
name. Returns null if no Resource could be found. |
public Enumeration getResources(String name) {
return getResources(name, true);
}
|
public Enumeration getResources(String name,
boolean check) {
return new Enumeration< Resource >() {
private int index = 0;
private Resource res = null;
private boolean next() {
if (res != null) {
return true;
} else {
Loader loader;
while ((loader = getLoader(index++)) != null) {
res = loader.getResource(name, check);
if (res != null) {
return true;
}
}
return false;
}
}
public boolean hasMoreElements() {
return next();
}
public Resource nextElement() {
if (!next()) {
throw new NoSuchElementException();
}
Resource r = res;
res = null;
return r;
}
};
}
Finds all resources on the URL search path with the given name.
Returns an enumeration of the Resource objects. |
public URL[] getURLs() {
synchronized (urls) {
return path.toArray(new URL[path.size()]);
}
}
Returns the original search path of URLs. |
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;
}
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. |