import java.io.*;
import java.net.*;
import java.util.*;
public class FileClassLoader extends /* superclass */ {
private String root;
public FileClassLoader (String rootDir) {
if (rootDir == null)
throw new IllegalArgumentException ("Null root directory");
root = rootDir;
}
protected Class loadClass (String name, boolean resolve)
throws ClassNotFoundException {
// Since all support classes of loaded class use same class loader
// must check subclass cache of classes for things like Object
// Class loaded yet?
if (c == null) {
// Convert class name argument to filename
// Convert package names into subdirectories
String filename = name.replace ('.', File.separatorChar) + ".class";
try {
// Load class data from file and save in byte array
// Convert byte array to Class
// If failed, throw exception
} catch (IOException e) {
throw new ClassNotFoundException ("Error reading file: " + filename);
}
}
// Resolve class definition if approrpriate
// Return class just created
return /* ? */ ;
}
private byte[] loadClassData (String filename)
throws IOException {
// Create a file object relative to directory provided
File f = new File (root, filename);
// Get size of class file
int size = (int)f.length();
// Reserve space to read
byte buff[] = new byte[size];
// Get stream to read from
FileInputStream fis = new FileInputStream(f);
DataInputStream dis = new DataInputStream (fis);
// Read in data
dis.readFully (buff);
// close stream
dis.close();
// return data
return buff;
}
}