SandMark version 2.0


sandmark.util
Class ClassFileCollection

java.lang.Object
  |
  +--sandmark.util.ClassFileCollection

public class ClassFileCollection
extends java.lang.Object

The sandmark.util.ClassFileCollection class provides methods for accessing a collection of files including Java bytecode files. Conceptually, the collection is like an editable jar file. Actually, it is a hidden directory of files. When no longer needed, a collection should be explicitly closed to avoid leaving debris in /tmp.


Constructor Summary
ClassFileCollection()
          Constructs a new, empty collection.
ClassFileCollection(java.lang.String filename)
          Constructs a collection and initializes it with the contents of a Jar file.
 
Method Summary
 void add(java.lang.String filename, byte[] data)
          Adds or replaces a file in this collection.
 void add(java.lang.String filename, java.io.File source)
          Adds or replaces a file in this collection.
 void addClass(EDU.purdue.cs.bloat.reflect.ClassInfo c)
          Adds or replaces a class in this collection, given a BLOAT ClassInfo.
 void addClass(de.fub.bytecode.classfile.JavaClass c)
          Adds or replaces a class in this collection, given a JavaClass.
 java.util.Iterator classes()
          Returns an iterator that produces the names of the classes contained in this collection.
 void close()
          Closes this collection, rendering it invalid.
 void delete(java.lang.String filename)
          Deletes a file from this collection.
 void deleteClass(java.lang.String classname)
          Deletes a class from the collection.
 java.util.Iterator files()
          Returns an iterator that produces the names of the files contained in this collection.
protected  void finalize()
          Finalizes this collection by closing it.
 byte[] get(java.lang.String filename)
          Extracts a member of this collection.
 void get(java.lang.String filename, java.io.File dest)
          Extracts a member of this collection and saves it in a file.
 de.fub.bytecode.classfile.JavaClass getClass(java.lang.String classname)
          Extracts a class as a JavaClass.
 EDU.purdue.cs.bloat.file.ClassFile getClassFile(java.lang.String classname)
          Extracts a class as a BLOAT ClassFile.
 java.lang.String getClassPath()
          Returns the classpath associated with the BLOAT ClassFileLoader.
 EDU.purdue.cs.bloat.file.ClassFileLoader getLoader()
          Returns the BLOAT ClassFileLoader associated with this ClassFileCollection.
 java.lang.String getMain()
          Returns the main-class attribute of the collection, or null if no main class has been set.
 java.util.jar.Manifest getManifest()
          Returns the attribute manifest associated with this collection.
 void optimise_saveJar(java.lang.String filename)
          Optimises and Saves this collection in a new Jar file.
 void saveJar(java.util.jar.JarOutputStream js)
           
 void saveJar(java.lang.String filename)
          Saves this collection in a new Jar file.
 void setMain(java.lang.String classname)
          Sets the main-class attribute of this collection, or clears it if the argument is null.
 java.lang.String toString()
          Returns a String representation of this ClassFileCollection.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ClassFileCollection

public ClassFileCollection()
                    throws java.io.IOException
Constructs a new, empty collection.


ClassFileCollection

public ClassFileCollection(java.lang.String filename)
                    throws java.io.IOException
Constructs a collection and initializes it with the contents of a Jar file.

Method Detail

saveJar

public final void saveJar(java.util.jar.JarOutputStream js)
                   throws java.io.IOException
java.io.IOException

saveJar

public final void saveJar(java.lang.String filename)
                   throws java.io.IOException
Saves this collection in a new Jar file.

java.io.IOException

optimise_saveJar

public void optimise_saveJar(java.lang.String filename)
                      throws java.io.IOException
Optimises and Saves this collection in a new Jar file.

java.io.IOException

close

public void close()
           throws java.io.IOException
Closes this collection, rendering it invalid.

java.io.IOException

finalize

protected void finalize()
                 throws java.lang.Throwable
Finalizes this collection by closing it.

Overrides:
finalize in class java.lang.Object
java.lang.Throwable

getManifest

public java.util.jar.Manifest getManifest()
Returns the attribute manifest associated with this collection. The manifest is included if the collection is saved as a Jar file.


get

public byte[] get(java.lang.String filename)
           throws java.io.IOException
Extracts a member of this collection.

java.io.IOException

get

public void get(java.lang.String filename,
                java.io.File dest)
         throws java.io.IOException
Extracts a member of this collection and saves it in a file.

java.io.IOException

add

public void add(java.lang.String filename,
                java.io.File source)
         throws java.io.IOException
Adds or replaces a file in this collection.

java.io.IOException

add

public void add(java.lang.String filename,
                byte[] data)
         throws java.io.IOException
Adds or replaces a file in this collection.

java.io.IOException

delete

public void delete(java.lang.String filename)
            throws java.io.IOException
Deletes a file from this collection.

java.io.IOException

files

public java.util.Iterator files()
                         throws java.io.IOException
Returns an iterator that produces the names of the files contained in this collection.

java.io.IOException

getMain

public java.lang.String getMain()
Returns the main-class attribute of the collection, or null if no main class has been set.


setMain

public void setMain(java.lang.String classname)
Sets the main-class attribute of this collection, or clears it if the argument is null.


getClass

public de.fub.bytecode.classfile.JavaClass getClass(java.lang.String classname)
                                             throws java.io.IOException
Extracts a class as a JavaClass.

java.io.IOException

addClass

public void addClass(de.fub.bytecode.classfile.JavaClass c)
              throws java.io.IOException
Adds or replaces a class in this collection, given a JavaClass.

java.io.IOException

getClassFile

public EDU.purdue.cs.bloat.file.ClassFile getClassFile(java.lang.String classname)
                                                throws java.lang.ClassNotFoundException
Extracts a class as a BLOAT ClassFile.

java.lang.ClassNotFoundException

addClass

public void addClass(EDU.purdue.cs.bloat.reflect.ClassInfo c)
              throws java.io.IOException
Adds or replaces a class in this collection, given a BLOAT ClassInfo. The argument class must have been loaded using getClassFile() or using the ClassFileLoader returned by getLoader().

java.io.IOException

getLoader

public EDU.purdue.cs.bloat.file.ClassFileLoader getLoader()
Returns the BLOAT ClassFileLoader associated with this ClassFileCollection. The output directory of this loader should not be changed.


getClassPath

public java.lang.String getClassPath()
Returns the classpath associated with the BLOAT ClassFileLoader.


deleteClass

public void deleteClass(java.lang.String classname)
                 throws java.io.IOException
Deletes a class from the collection.

java.io.IOException

classes

public java.util.Iterator classes()
                           throws java.io.IOException
Returns an iterator that produces the names of the classes contained in this collection.

java.io.IOException

toString

public java.lang.String toString()
Returns a String representation of this ClassFileCollection.

Overrides:
toString in class java.lang.Object

SandMark version 2.0

Mon Jun 17 12:30:47 MST 2002