Package EDU.purdue.cs.bloat.file
Class ClassFileLoader
- java.lang.Object
-
- EDU.purdue.cs.bloat.file.ClassFileLoader
-
- All Implemented Interfaces:
ClassInfoLoader
- Direct Known Subclasses:
JarFileCommitter
public class ClassFileLoader extends java.lang.Object implements ClassInfoLoader
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 Modifier and Type Field Description static booleanDEBUGstatic booleanUSE_SYSTEM_CLASSES
-
Constructor Summary
Constructors Constructor Description ClassFileLoader()Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidappendClassPath(java.lang.String morePath)Adds to the classpath (CLASSPATH = CLASSPATH + morePath).voiddone()Signifies that we are done with thisClassFileLoaderjava.lang.StringgetClassPath()Returns the path used to search for class files.ClassInfoloadClass(java.lang.String name)Loads the class with the given name.ClassInfo[]loadClassesFromZipFile(java.util.zip.ZipFile zipFile)Loads all of the classes that are contained in a zip (or jar) file.ClassInfonewClass(int modifiers, int classIndex, int superClassIndex, int[] interfaceIndexes, java.util.List constants)Creates a new class or interface.java.io.FileoutputDir()Get the directory into which commited class files should be written.java.io.OutputStreamoutputStreamFor(ClassInfo info)Returns an OutputStream to which a class file should be written.protected java.io.OutputStreamoutputStreamFor(java.lang.String name)Returns anOutputStreamto which somed named entity is written.voidprependClassPath(java.lang.String morePath)Adds to the classpath (CLASSPATH = morePath + CLASSPATH).voidsetClassPath(java.lang.String classpath)Sets the classpath.voidsetOutputDir(java.io.File dir)Set the directory into which commited class files should be written.voidsetVerbose(boolean verbose)voidwriteEntry(byte[] bytes, java.lang.String name)Writes a bunch ofbytes to an output entry with the given name.
-
-
-
Method Detail
-
setVerbose
public void setVerbose(boolean verbose)
-
setClassPath
public void setClassPath(java.lang.String classpath)
Sets the classpath.
-
appendClassPath
public void appendClassPath(java.lang.String morePath)
Adds to the classpath (CLASSPATH = CLASSPATH + morePath).
-
prependClassPath
public void prependClassPath(java.lang.String morePath)
Adds to the classpath (CLASSPATH = morePath + CLASSPATH).
-
getClassPath
public java.lang.String getClassPath()
Returns the path used to search for class files.
-
loadClassesFromZipFile
public ClassInfo[] loadClassesFromZipFile(java.util.zip.ZipFile zipFile) throws java.lang.ClassNotFoundException
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:
java.lang.ClassNotFoundException
-
newClass
public ClassInfo newClass(int modifiers, int classIndex, int superClassIndex, int[] interfaceIndexes, java.util.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
public ClassInfo loadClass(java.lang.String name) throws java.lang.ClassNotFoundException
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:
java.lang.ClassNotFoundException- The class cannot be found in the class path.- See Also:
ClassInfo
-
setOutputDir
public void setOutputDir(java.io.File dir)
Set the directory into which commited class files should be written.- Parameters:
dir- The directory.
-
outputDir
public java.io.File outputDir()
Get the directory into which commited class files should be written.
-
writeEntry
public void writeEntry(byte[] bytes, java.lang.String name) throws java.io.IOExceptionWrites a bunch ofbytes to an output entry with the given name.- Throws:
java.io.IOException
-
outputStreamFor
public java.io.OutputStream outputStreamFor(ClassInfo info) throws java.io.IOException
Returns an OutputStream to which a class file should be written.- Specified by:
outputStreamForin interfaceClassInfoLoader- Throws:
java.io.IOException
-
outputStreamFor
protected java.io.OutputStream outputStreamFor(java.lang.String name) throws java.io.IOExceptionReturns anOutputStreamto which somed named entity is written. Any forward slashes in the name are replaced byFile.separatorChar.- Throws:
java.io.IOException
-
done
public void done() throws java.io.IOExceptionSignifies that we are done with thisClassFileLoader- Throws:
java.io.IOException
-
-