Jode 1.90-CVS
Build Aug 6, 2004

net.sf.jode.bytecode
Class ClassPath.Location

java.lang.Object
  extended bynet.sf.jode.bytecode.ClassPath.Location
Enclosing class:
ClassPath

public static class ClassPath.Location
extends java.lang.Object

A location is a single component of the ClassPath. It provides methods to find files, list all files and reading them.
Files and directories are always separated by "/" in this class, even under Windows where the default is a "\". This behaviour is consistent with that of ZipFile.
You can extend this class to provide your own custom locations.


Constructor Summary
ClassPath.Location()
           
 
Method Summary
protected  boolean exists(java.lang.String file)
          Tells whether there exists a file or directory with the given name at this location.
protected  java.io.InputStream getFile(java.lang.String file)
          Returns an input stream that reads the given file.
protected  boolean isDirectory(java.lang.String file)
          Tells whether there exists a directory (or package) with the given name at this location.
protected  java.util.Enumeration listFiles(java.lang.String directory)
          Lists the files and subdirectory in a directory.
protected  boolean loadClass(ClassInfo clazz, int howMuch)
          Loads a class from this location and fills it with the given information.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassPath.Location

public ClassPath.Location()
Method Detail

exists

protected boolean exists(java.lang.String file)
Tells whether there exists a file or directory with the given name at this location.
The default implementation returns false.

Parameters:
file - the name of the file, directories are always separated by "/".
Returns:
true if a file exists at this location.

isDirectory

protected boolean isDirectory(java.lang.String file)
Tells whether there exists a directory (or package) with the given name at this location.
The default implementation returns false.

Parameters:
file - the name of the directory, subdirectories are always separated by "/".
Returns:
true if a file exists at this location.

getFile

protected java.io.InputStream getFile(java.lang.String file)
                               throws java.io.IOException
Returns an input stream that reads the given file. It is only called for files for which exists returns true.
The default implementation returns null.

Parameters:
file - the name of the file, subdirectories are always separated by "/".
Returns:
an input stream for the given file, or null if file was not found.
Throws:
java.io.IOException - if an io exception occured while opening the file.

listFiles

protected java.util.Enumeration listFiles(java.lang.String directory)
Lists the files and subdirectory in a directory. This is only called for directories for which isDirectory returns true.
The objects returned by the nextElement() method of the Enumeration should be of type String and contain the file resp directory name without any parent directory names.
Note that this method is also used by ClassPath.listClassesAndPackages(java.lang.String).
The default implementation returns null, which is equivalent to an empty enumeration.

Parameters:
directory - the name of the directory, subdirectories are always separated by "/".
Returns:
an enumeration, listing the file names. It may return null instead of an empty enumeration.

loadClass

protected boolean loadClass(ClassInfo clazz,
                            int howMuch)
                     throws java.io.IOException,
                            ClassFormatException
Loads a class from this location and fills it with the given information.
The default implementation will get the corresponding ".class" file via getFile() and fill the information from the stream. So normally there is no need to override this method.
If you want to build classes on the fly, for example if you wrote a parser for java files and want to build class files from them, you can override this method.

Parameters:
clazz - the dot separated full qualified class name.
howMuch - the amount of information to load
Returns:
true, if loading the class was successful, false if it was not found.
Throws:
ClassFormatException - if class format is illegal
java.io.IOException - if an io exception occured while reading the class.
See Also:
ClassInfo.read(java.io.DataInputStream, int)

Jode 1.90-CVS
Build Aug 6, 2004

Copyright © 1998-2004 by Jochen Hoenicke.