diff options
author | Anthony Green <green@gcc.gnu.org> | 2000-11-26 03:58:56 +0000 |
---|---|---|
committer | Anthony Green <green@gcc.gnu.org> | 2000-11-26 03:58:56 +0000 |
commit | 31280fb7c47e6a32289b4dfc47880a9f22a9d9b4 (patch) | |
tree | 271c97444f9f312ff7d98c59c17993b4b9218ea3 /libjava/java/net/URLClassLoader.java | |
parent | 1786009e06fdea320bf13b65f130632853c9386a (diff) | |
download | gcc-31280fb7c47e6a32289b4dfc47880a9f22a9d9b4.zip gcc-31280fb7c47e6a32289b4dfc47880a9f22a9d9b4.tar.gz gcc-31280fb7c47e6a32289b4dfc47880a9f22a9d9b4.tar.bz2 |
prims.cc (_Jv_NewObjectArray): Undo placement change.
2000-11-25 Anthony Green <green@redhat.com>
* prims.cc (_Jv_NewObjectArray): Undo placement change.
(_Jv_NewPrimArray): Likewise.
* gcj/array.h (__JArray): Undo const change. Removed constructor.
(class JArray): Removed constructor.
* java/lang/Thread.java (context_class_loader): New private data.
(getContextClassLoader): New method.
(setContextClassLoader): New method.
(Thread): Initialize context_class_loader.
* java/net/URLClassLoader.java: Import java.util.Enumeration.
(getResource): Rename to findResource.
(findResource): New method. Used to be getResource.
(getResourceAsStream): Deleted.
(jarFileize): Extracted logic from URLClassLoader constructor into
this new private method.
(addURL): New protected method.
(URLClassLoader): Call jarFileize. Use addElement instead of
insertElementAt.
(findResources): New method.
* java/lang/ClassLoader.java: Import java.util.Enumeration.
(getResource): Implement correct logic.
(findResource): New method.
(getResources): New method.
(findClass): Create a ClassNotFoundException with the name of the
class rather than nothing at all.
(defineClass) Only throw ClassFormatError.
* java/lang/Class.java (forName): New method.
* java/lang/Class.h (forName): New method.
* java/lang/natClass.cc (forName): New method.
From-SVN: r37751
Diffstat (limited to 'libjava/java/net/URLClassLoader.java')
-rw-r--r-- | libjava/java/net/URLClassLoader.java | 136 |
1 files changed, 87 insertions, 49 deletions
diff --git a/libjava/java/net/URLClassLoader.java b/libjava/java/net/URLClassLoader.java index 441b7ca..eeec882 100644 --- a/libjava/java/net/URLClassLoader.java +++ b/libjava/java/net/URLClassLoader.java @@ -10,6 +10,7 @@ package java.net; import java.io.*; import java.util.jar.*; +import java.util.Enumeration; import java.util.Vector; public class URLClassLoader extends ClassLoader @@ -42,6 +43,56 @@ public class URLClassLoader extends ClassLoader this (urls, parent, null); } + // A File URL may actually be a Jar URL. Convert if possible. + private URL jarFileize (URL url) + { + if (! url.getProtocol ().equals ("jar")) + { + String f = url.getFile (); + + // If it ends with '/' we'll take it for a directory, + // otherwise it's a jar file. This is how JDK 1.2 defines + // it, so we will not try to be smart here. + if (f.charAt (f.length ()-1) != '/') + { + try + { + url = new URL ("jar", "", -1, (url.toExternalForm ())+"!/", + getHandler0 ("jar")); + } + catch (MalformedURLException x) + { + /* ignore */ + } + } + } + return url; + } + + protected void addURL (URL url) + { + JarURLConnection conn = null; + + // Convert a Jar File URL into Jar URL if possible. + url = jarFileize (url); + + path.addElement (url); + + if (url.getProtocol ().equals ("jar")) + { + try + { + conn = (JarURLConnection) url.openConnection (); + } + catch (java.io.IOException x) + { + /* ignore */ + } + } + + info.addElement (conn); + } + public URLClassLoader (URL[] urls, ClassLoader parent, URLStreamHandlerFactory fac) { @@ -61,31 +112,10 @@ public class URLClassLoader extends ClassLoader for (int i = 0; i < urls.length; i++) { - URL u = urls[i]; + // Convert a Jar File URL into a Jar URL is possible. + URL u = jarFileize(urls[i]); - // If it is a jar url, then we'll search it as is. - if (! u.getProtocol ().equals ("jar")) - { - String f = u.getFile (); - - // If it ends with '/' we'll take it for a directory, - // otherwise it's a jar file. This is how JDK 1.2 defines - // it, so we will not try to be smart here. - if (f.charAt (f.length ()-1) != '/') - { - try - { - u = new URL ("jar", "", -1, (u.toExternalForm ())+"!/", - getHandler0 ("jar")); - } - catch (MalformedURLException x) - { - /* ignore */ - } - } - } - - path.insertElementAt (u, i); + path.addElement (u); if (u.getProtocol ().equals ("jar")) { @@ -98,75 +128,83 @@ public class URLClassLoader extends ClassLoader { /* ignore */ } - info.insertElementAt (conn, i); + info.addElement (conn); } else { - info.insertElementAt (null, i); + info.addElement (null); } } } + + public URL[] getURLs () + { + URL[] urls = new URL[path.size()]; + path.copyInto (urls); + return urls; + } - public URL getResource (String name) + public Enumeration findResources (String name) { + Vector results = new Vector (); + for (int i = 0; i < path.size(); i++) { - URL u = (URL)path.elementAt (i); - + URL u = (URL)path.elementAt (i); + try { JarURLConnection conn = (JarURLConnection) info.elementAt (i); - + if (conn != null) { if (conn.getJarFile().getJarEntry (name) != null) - return new URL(u, name, getHandler0 (u.getProtocol())); + results.addElement (new URL(u, name, getHandler0 (u.getProtocol()))); } else { URL p = new URL (u, name, getHandler0 (u.getProtocol())); - + InputStream is = p.openStream(); if (is != null) { is.close(); - return p; + results.addElement (p); } } - + // if we get an exception ... try the next path element } catch (IOException x) { continue; } } - - return null; + + return results.elements (); } - /** IN jdk 1.2 this method is not overridden, but we gain performance - by doing so. - */ - - public InputStream getResourceAsStream (String name) + public URL findResource (String name) { for (int i = 0; i < path.size(); i++) { - URL u = (URL)path.elementAt (i); + URL u = (URL)path.elementAt (i); try { JarURLConnection conn = (JarURLConnection) info.elementAt (i); - + if (conn != null) { - JarFile file = conn.getJarFile (); - JarEntry ent = file.getJarEntry (name); - if (ent != null) - return file.getInputStream(ent); + if (conn.getJarFile().getJarEntry (name) != null) + return new URL(u, name, getHandler0 (u.getProtocol())); } else { - InputStream is = new URL(u, name, getHandler0 (u.getProtocol())).openStream(); + URL p = new URL (u, name, getHandler0 (u.getProtocol())); + + InputStream is = p.openStream(); if (is != null) - return is; + { + is.close(); + return p; + } } // if we get an exception ... try the next path element |