|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.deltax.util.JDK12ClassFileFinder
This class emulates JDK 1.2 behaviour for finding class, providing direct access to the files / streams.
Of course, it works only when classes are actually loaded from a filesystem.
Field Summary | |
protected java.util.HashMap |
classCache
Maps class names to Object[2] arrays containing file and classfile (File, byte[]) |
protected boolean |
classCacheOn
|
protected java.lang.String |
classPath
The application class path used by this classFileFinder |
protected java.util.Enumeration |
classPathDirs
Caches results of getClassPathDirs()
If the classpath changes, it must be invalidated. |
protected java.util.HashSet |
missingFilesNotified
|
Constructor Summary | |
JDK12ClassFileFinder()
Creates a classfinder which looks (besides system directories) in $java.class.path |
|
JDK12ClassFileFinder(java.lang.String classPath)
Creates a classfinder which looks (besides system directories) in the given class path |
Method Summary | |
protected java.lang.String |
classNameToEntry(java.lang.String className)
Converts a fully qualified externalized java class name into a zip file entry. |
protected java.lang.String |
classNameToPath(java.lang.String className)
Converts a fully qualified externalized java class name into a relative file path. |
void |
clearCorruptFiles()
Empty the set of files considered corrupted since they failed to open when the finder was searching for classes, so that subsequent work will not ignore them. |
java.io.File |
findClassFile(java.lang.String className)
This method emulates 1.2 behaviour for class finding - which means: - it first searches into the $java.home/lib/ and $java.home/lib/*.jar; - then in $java.ext.dirs/*.jar; - eventually in $java.class.path |
protected java.io.File[] |
findJarsInPath(java.io.File path)
Find the JAR files in the given path |
java.io.File |
findResourceFile(java.lang.String resource)
Find a resource in the filesystem. |
byte[] |
getBytes(java.lang.String className)
Return the byte array for the class |
byte[] |
getClassBytes(java.lang.String className)
Returns a byte array with the bytecode for the class * @param className the name of the class to find * @return byte[] the bytecode for the class * @throws IOException if a problem arises while loading the bytecode * @throws ClassNotFoundException if the class definition cannot be found |
protected java.util.Enumeration |
getClassPathDirs()
|
java.util.Set |
getCorruptFiles()
Return the set, possibly empty, of files which couldn't be opened when the finder was searching for classes |
byte[] |
getResourceBytes(java.lang.String resource)
Return a byte array with the bytes for the resource, or null if the resource cannot be found |
java.lang.String |
getSupportedLoadingScheme()
Returns the supported loading scheme |
boolean |
isClassCacheOn()
Returns the classCacheOn. |
boolean |
isJar(java.io.File f)
Just checks if the file ends with .jar |
static void |
main(java.lang.String[] args)
|
java.io.InputStream |
openClass(java.lang.String className)
Open class data. |
protected java.io.InputStream |
openClassInJar(java.lang.String className,
java.io.File jarFile)
Open class data in a JAR file |
java.io.InputStream |
openResource(java.lang.String resource)
Return the stream associated to a resource in the filesystem, or null if such resource cannot be found. |
protected java.io.File |
searchJars(java.lang.String className,
java.io.File[] jars)
Searches jar files for a given class path |
void |
setClassCacheOn(boolean classCacheOn)
Sets the classCacheOn. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected java.lang.String classPath
protected java.util.Enumeration classPathDirs
getClassPathDirs()
If the classpath changes, it must be invalidated.
protected java.util.HashSet missingFilesNotified
protected java.util.HashMap classCache
protected boolean classCacheOn
Constructor Detail |
public JDK12ClassFileFinder(java.lang.String classPath)
classPath
- the search class pathpublic JDK12ClassFileFinder()
Method Detail |
public java.lang.String getSupportedLoadingScheme()
getSupportedLoadingScheme
in interface ClassFileFinder
public java.io.InputStream openClass(java.lang.String className) throws java.io.IOException, java.lang.ClassNotFoundException
openClass
in interface ClassFileFinder
className
- the name of the class to find
java.lang.ClassNotFoundException
- if the class is not found
java.io.IOException
- if an I/O Exception occurspublic java.io.File findClassFile(java.lang.String className) throws java.io.IOException, java.lang.ClassNotFoundException
findClassFile
in interface ClassFileFinder
className
- the name of the class to find
java.lang.ClassNotFoundException
- if the class is not found
java.io.IOException
- if an I/O Exception occurspublic byte[] getBytes(java.lang.String className) throws java.io.IOException, java.lang.ClassNotFoundException
java.lang.ClassNotFoundException
- if the class is not found in the JAR file
java.io.IOException
- if an I/O Exception occurspublic boolean isJar(java.io.File f)
f
- the file to check
protected java.io.InputStream openClassInJar(java.lang.String className, java.io.File jarFile) throws java.io.IOException, java.lang.ClassNotFoundException
java.lang.ClassNotFoundException
- if the class is not found in the JAR file
java.io.IOException
- if an I/O Exception occurs
java.io.FileNotFoundException
- if the JAR file does not existprotected java.io.File searchJars(java.lang.String className, java.io.File[] jars) throws java.io.IOException, java.lang.ClassNotFoundException
className
- the name of the class to findjars
- an array of JAR file objects
java.lang.ClassNotFoundException
- if the class is not found
java.io.IOException
- if an I/O Exception occursprotected java.io.File[] findJarsInPath(java.io.File path)
path
- the path to search in
protected java.lang.String classNameToPath(java.lang.String className)
className
- the name of the class to find
protected java.lang.String classNameToEntry(java.lang.String className)
className
- the name of the class to find
protected java.util.Enumeration getClassPathDirs()
public byte[] getClassBytes(java.lang.String className) throws java.io.IOException, java.lang.ClassNotFoundException
ClassFileFinder
getClassBytes
in interface ClassFileFinder
java.io.IOException
java.lang.ClassNotFoundException
ClassFileFinder.getClassBytes(java.lang.String)
public java.io.InputStream openResource(java.lang.String resource) throws java.io.IOException
The returned stream is not buffered.
openResource
in interface ResourceFileFinder
resource
- the resource path
java.io.IOException
- if a problem arises accessing the resourcecom.deltax.util.ResourceFileFinder#findResource(java.lang.String)
public java.io.File findResourceFile(java.lang.String resource) throws java.io.IOException
This class implements findResource by operating as findClassFile()
and attempting to locate the resource within directories or JAR
files therein.
Resource loading from other than filesystem is not supported.
findResourceFile
in interface ResourceFileFinder
resource
- the resource path
java.io.IOException
- if a problem arises accessing the resourcecom.deltax.util.ResourceFileFinder#findResource(java.lang.String)
public byte[] getResourceBytes(java.lang.String resource) throws java.io.IOException
getResourceBytes
in interface ResourceFileFinder
java.io.IOException
public static void main(java.lang.String[] args) throws java.lang.Exception
java.lang.Exception
public boolean isClassCacheOn()
public void setClassCacheOn(boolean classCacheOn)
classCacheOn
- The classCacheOn to setpublic java.util.Set getCorruptFiles()
public void clearCorruptFiles()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |