Class ClassFileLoader

java.lang.Object
EDU.purdue.cs.bloat.file.ClassFileLoader
All Implemented Interfaces:
ClassInfoLoader
Direct Known Subclasses:
JarFileCommitter

public class ClassFileLoader extends 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 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

      public void setClassPath(String classpath)
      Sets the classpath.
    • appendClassPath

      public void appendClassPath(String morePath)
      Adds to the classpath (CLASSPATH = CLASSPATH + morePath).
    • prependClassPath

      public void prependClassPath(String morePath)
      Adds to the classpath (CLASSPATH = morePath + CLASSPATH).
    • getClassPath

      public String getClassPath()
      Returns the path used to search for class files.
    • loadClassesFromZipFile

      public ClassInfo[] loadClassesFromZipFile(ZipFile zipFile) throws 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:
      ClassNotFoundException
    • newClass

      public ClassInfo newClass(int modifiers, int classIndex, int superClassIndex, int[] interfaceIndexes, List constants)
      Description copied from interface: ClassInfoLoader
      Creates a new class or interface.
      Specified by:
      newClass in interface ClassInfoLoader
      Parameters:
      modifiers - The modifiers describing the newly-created class
      classIndex - The index of the name of the newly-created class in its constant pool
      superClassIndex - The index of the name of the newly-created class's superclass in its constant pool
      interfaceIndexes - The indexes of the names of the interfaces that the newly-created class implements
      constants - The constant pool for the newly created class (a list of Constants).
    • loadClass

      public ClassInfo loadClass(String name) throws 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:
      loadClass in interface ClassInfoLoader
      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

      public void setOutputDir(File dir)
      Set the directory into which commited class files should be written.
      Parameters:
      dir - The directory.
    • outputDir

      public File outputDir()
      Get the directory into which commited class files should be written.
    • writeEntry

      public void writeEntry(byte[] bytes, String name) throws IOException
      Writes a bunch of bytes to an output entry with the given name.
      Throws:
      IOException
    • outputStreamFor

      public OutputStream outputStreamFor(ClassInfo info) throws IOException
      Returns an OutputStream to which a class file should be written.
      Specified by:
      outputStreamFor in interface ClassInfoLoader
      Throws:
      IOException
    • outputStreamFor

      protected OutputStream outputStreamFor(String name) throws IOException
      Returns an OutputStream to which somed named entity is written. Any forward slashes in the name are replaced by File.separatorChar.
      Throws:
      IOException
    • done

      public void done() throws IOException
      Signifies that we are done with this ClassFileLoader
      Throws:
      IOException