Class ClassFileLoader
java.lang.Object
EDU.purdue.cs.bloat.file.ClassFileLoader
- All Implemented Interfaces:
ClassInfoLoader
- Direct Known Subclasses:
JarFileCommitter
ClassFileLoder provides an interface for loading classes from files. The
actual loading is done by the ClassFile itself.
Classes may be specified by their full package name (java.lang.String), or by the name of their class file (myclasses/Test.class). The class path may contain directories or Zip or Jar files. Any classes that are written back to disk ("committed") are placed in the output directory.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidappendClassPath(String morePath) Adds to the classpath (CLASSPATH = CLASSPATH + morePath).voiddone()Signifies that we are done with thisClassFileLoaderReturns the path used to search for class files.Loads the class with the given name.loadClassesFromZipFile(ZipFile zipFile) Loads all of the classes that are contained in a zip (or jar) file.newClass(int modifiers, int classIndex, int superClassIndex, int[] interfaceIndexes, List constants) Creates a new class or interface.Get the directory into which commited class files should be written.outputStreamFor(ClassInfo info) Returns an OutputStream to which a class file should be written.protected OutputStreamoutputStreamFor(String name) Returns anOutputStreamto which somed named entity is written.voidprependClassPath(String morePath) Adds to the classpath (CLASSPATH = morePath + CLASSPATH).voidsetClassPath(String classpath) Sets the classpath.voidsetOutputDir(File dir) Set the directory into which commited class files should be written.voidsetVerbose(boolean verbose) voidwriteEntry(byte[] bytes, String name) Writes a bunch ofbytes to an output entry with the given name.
-
Field Details
-
DEBUG
public static boolean DEBUG -
USE_SYSTEM_CLASSES
public static boolean USE_SYSTEM_CLASSES
-
-
Constructor Details
-
ClassFileLoader
public ClassFileLoader()Constructor. The classpath initially consists of the contents of the java.class.path and sun.boot.class.path system properties.
-
-
Method Details
-
setVerbose
public void setVerbose(boolean verbose) -
setClassPath
Sets the classpath. -
appendClassPath
Adds to the classpath (CLASSPATH = CLASSPATH + morePath). -
prependClassPath
Adds to the classpath (CLASSPATH = morePath + CLASSPATH). -
getClassPath
Returns the path used to search for class files. -
loadClassesFromZipFile
Loads all of the classes that are contained in a zip (or jar) file. Returns an array of the ClassInfos for the classes in the zip file.- Throws:
ClassNotFoundException
-
newClass
public ClassInfo newClass(int modifiers, int classIndex, int superClassIndex, int[] interfaceIndexes, List constants) Description copied from interface:ClassInfoLoaderCreates a new class or interface.- Specified by:
newClassin interfaceClassInfoLoader- Parameters:
modifiers- The modifiers describing the newly-created classclassIndex- The index of the name of the newly-created class in its constant poolsuperClassIndex- The index of the name of the newly-created class's superclass in its constant poolinterfaceIndexes- The indexes of the names of the interfaces that the newly-created class implementsconstants- The constant pool for the newly created class (a list ofConstants).
-
loadClass
Loads the class with the given name. Searches the class path, including zip files, for the class and then returns a data stream for the class file.- Specified by:
loadClassin interfaceClassInfoLoader- Parameters:
name- The name of the class to load, including the package name.- Returns:
- A ClassInfo for the class.
- Throws:
ClassNotFoundException- The class cannot be found in the class path.- See Also:
-
setOutputDir
Set the directory into which commited class files should be written.- Parameters:
dir- The directory.
-
outputDir
Get the directory into which commited class files should be written. -
writeEntry
Writes a bunch ofbytes to an output entry with the given name.- Throws:
IOException
-
outputStreamFor
Returns an OutputStream to which a class file should be written.- Specified by:
outputStreamForin interfaceClassInfoLoader- Throws:
IOException
-
outputStreamFor
Returns anOutputStreamto which somed named entity is written. Any forward slashes in the name are replaced byFile.separatorChar.- Throws:
IOException
-
done
Signifies that we are done with thisClassFileLoader- Throws:
IOException
-