Class NetworkClassLoader

  extended byjava.lang.ClassLoader
      extended byfi.hut.tml.xsmiles.NetworkClassLoader

public class NetworkClassLoader
extends java.lang.ClassLoader

The correct name for this class should be URLClassLoader. But there is already a class by that name in JDK1.2. I have had quite a few problems with URLClassLoader in past, so I ended up writing this ClassLoader. I found that the Java 2's URLClassLoader, does not close the Jar file once opened. It is a pretty good optimization step, but if you modify the class in the jar file, it does not pick it up. Some operating systems may not let you modify the jar file while it is still open. IMHO, it does make sense to close the jar file after you are done reading the class data. But this approach may not get you the performance of the URLClassLoader, but it works in all cases and also runs on JDK1.1. I have enhanced this class loader to read all the zip/jar entries once & cache the data, so that there is no overhead of opening/closing jar file to pick up each entry.

Harish Prabandham

Nested Class Summary
 class NetworkClassLoader.URLResourceReader
          This implementation of URL Resource Reader assumes 2 types of base urls.
Constructor Summary
NetworkClassLoader(java.lang.ClassLoader parent)
          Creates a new instance of the class loader.
Method Summary
 void addURL( url)
          Adds the given URL to this class loader.
 void clear()
          This method resets this ClassLoader's state.
protected  java.lang.Class defineClass(java.lang.String classname, byte[] classdata)
          java.lang.ClassLoader's defineClass method is final, so the its subclasses cannot override this method.
protected  void finalize()
          This method resets this ClassLoader's state and resets the references for garbage collection.
 java.lang.Class findClass(java.lang.String name)
          Call this to bypass the implementation of loadClass. getResourceAsStream(java.lang.String name)
 java.util.Enumeration getURLs()
 java.lang.Class loadClass(java.lang.String name, boolean resolve)
protected  byte[] loadClassData(java.lang.String classname)
protected  byte[] loadResource(java.lang.String resource)
protected  byte[] loadResource( url, java.lang.String resourceName)
protected  void setParent(java.lang.ClassLoader parent)
          Sets the parent/delegate class loader.
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findResource, findResources, findSystemClass, getPackage, getPackages, getParent, getResource, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public NetworkClassLoader(java.lang.ClassLoader parent)
Creates a new instance of the class loader.

Method Detail


protected final void setParent(java.lang.ClassLoader parent)
Sets the parent/delegate class loader.


public void addURL( url)
Adds the given URL to this class loader. If the URL ends with "/", then it is assumed to be a directory otherwise, it is assumed to be a zip/jar file. If the same URL is added again, the URL is re-opened and this zip/jar file is used for serving any future class requests.


public java.util.Enumeration getURLs()
An enumeration of URLs where this class loader looks for classes.


public java.lang.Class findClass(java.lang.String name)
Call this to bypass the implementation of loadClass.


protected byte[] loadResource( url,
                              java.lang.String resourceName)


protected byte[] loadResource(java.lang.String resource)


protected byte[] loadClassData(java.lang.String classname)


public getResourceAsStream(java.lang.String name)
The resource as the input stream if such a resource exists, otherwise returns null.


protected java.lang.Class defineClass(java.lang.String classname,
                                      byte[] classdata)
java.lang.ClassLoader's defineClass method is final, so the its subclasses cannot override this method. But, this class calls this method in the loadClass() instead.

The class object.


public java.lang.Class loadClass(java.lang.String name,
                                 boolean resolve)
                          throws java.lang.ClassNotFoundException


public final void clear()
This method resets this ClassLoader's state. It completely removes all the URLs and classes in this class loader cache.


protected void finalize()
                 throws java.lang.Throwable
This method resets this ClassLoader's state and resets the references for garbage collection.


X-Smiles 1.2