Package eu.simuline.util
Class JavaPath
- java.lang.Object
-
- eu.simuline.util.JavaPath
-
public final class JavaPath extends java.lang.ObjectRepresents a path to find class and source files on. Created: Wed Jun 14 23:12:06 2006- Version:
- 1.0
- Author:
- Ernst Reissner
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classJavaPath.ClsSrcDetermines whether a class file or a source file is meant.(package private) static interfaceJavaPath.FileWrapperWrapps a file directly found within a directory or within a zip-archive which also includes jar-archives.(package private) static classJavaPath.OrdFileWrapperRepresents an ordinary fileJavaPath.OrdFileWrapper.fileon a file system.(package private) static classJavaPath.ZipEntryWrapperRepresents a fileJavaPath.ZipEntryWrapper.entrywhich is an entry in a zip-fileJavaPath.ZipEntryWrapper.zipFile.
-
Field Summary
Fields Modifier and Type Field Description private static charCLASS_SEPJava's class separator.separating classes from their packages and also packages from their subpackages.private static charFILE_SEPThe entry of propertyfile.separatoras a char.private static java.lang.StringINNER_CLASS_SEPJava's class separator$separating inner classes from their enclosing classes.private static java.lang.StringJAR_ENDFile ending.jaridentifying jar-files.private static intLEN_BUFFERThe length of a buffer to read at once.private static java.lang.StringPATH_SEPThe entry of propertypath.separator.private java.util.List<java.io.File>rootsThe list of entries of this path.private static java.lang.StringZIP_ENDFile ending.zipidentifying zip-files.
-
Constructor Summary
Constructors Constructor Description JavaPath(java.lang.String path)Creates a newJavaPathinstance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringabsFile2cls(java.io.File absFile, JavaPath.ClsSrc clsSrc)private java.lang.Stringcls2locFile(java.lang.String clsName, JavaPath.ClsSrc clsSrc)Converts a class name into the into the corresponding name of a local source file or class file.java.io.FilegetFile(java.lang.String localFilename)java.io.FilegetFile(java.lang.String clsName, JavaPath.ClsSrc clsSrc)Converts a class name into the corresponding source file or class file if possible.java.io.InputStreamgetInputStream(java.lang.String clsName)java.lang.StringgetLocFileName(java.io.File absFile)java.lang.StringlocFile2cls(java.lang.String locFileName, JavaPath.ClsSrc clsSrc)private JavaPath.FileWrapperlocFile2Wrapper(java.lang.String localFilename)Converts a local file name into the wrapper of the file found on the path.static voidmain(java.lang.String[] args)java.lang.StringtoString()
-
-
-
Field Detail
-
FILE_SEP
private static final char FILE_SEP
The entry of propertyfile.separatoras a char.
-
PATH_SEP
private static final java.lang.String PATH_SEP
The entry of propertypath.separator.
-
CLASS_SEP
private static final char CLASS_SEP
Java's class separator.separating classes from their packages and also packages from their subpackages.- See Also:
- Constant Field Values
-
INNER_CLASS_SEP
private static final java.lang.String INNER_CLASS_SEP
Java's class separator$separating inner classes from their enclosing classes.- See Also:
- Constant Field Values
-
ZIP_END
private static final java.lang.String ZIP_END
File ending.zipidentifying zip-files.- See Also:
- Constant Field Values
-
JAR_END
private static final java.lang.String JAR_END
File ending.jaridentifying jar-files.- See Also:
- Constant Field Values
-
LEN_BUFFER
private static final int LEN_BUFFER
The length of a buffer to read at once.- See Also:
- Constant Field Values
-
roots
private final java.util.List<java.io.File> roots
The list of entries of this path. This serves as root path for the source files and class files under consideration. CAUTION: Note that besides directories also.zip-files and.jar-files are allowed.
-
-
Constructor Detail
-
JavaPath
public JavaPath(java.lang.String path)
Creates a newJavaPathinstance. Essentially,rootsis initialized.- Parameters:
path- a path as aStringvalue. note that the entries of the path must not be the empty string.- Throws:
java.lang.IllegalArgumentException- if two path separators immediately follow on one another or if they stand at the beginning or at the end ofpath.
-
-
Method Detail
-
cls2locFile
private java.lang.String cls2locFile(java.lang.String clsName, JavaPath.ClsSrc clsSrc)Converts a class name into the into the corresponding name of a local source file or class file.- Parameters:
clsName- the name of the class as aStringvalue.clsSrc- aClsSrcwhich determines whether to convert the class name into a class file or into a source file.- Returns:
- the name of the local class or source file
of the given class.
Note that this is no absolute pathname of course:
rootsis not read.
-
getFile
public java.io.File getFile(java.lang.String clsName, JavaPath.ClsSrc clsSrc)Converts a class name into the corresponding source file or class file if possible.- Parameters:
clsName- the name of the class as aStringvalue.clsSrc- aClsSrcwhich determines whether to convert the class name into a class file or into a source file.- Returns:
- the source or class
Filecorresponding with the given classname if there is one; otherwise returnsnull. Note that if the file is found within a zip- or jar-file, a temporal file is created. In any case, the file returned exists unlessnullis returned.
-
getFile
public java.io.File getFile(java.lang.String localFilename)
-
getInputStream
public java.io.InputStream getInputStream(java.lang.String clsName) throws java.io.IOException- Throws:
java.io.IOException
-
locFile2Wrapper
private JavaPath.FileWrapper locFile2Wrapper(java.lang.String localFilename)
Converts a local file name into the wrapper of the file found on the path. Note that also within zip- or jar-file is searched.- Parameters:
localFilename- the name of a local file as aStringvalue.- Returns:
- a
FileWrapperrepresenting the first file found on the path with the appropriate name. If the file is found in a directory of the path, anJavaPath.OrdFileWrapperis returned, if it is found within a zip- or jar-file, aJavaPath.ZipEntryWrapperis returned.
-
getLocFileName
public java.lang.String getLocFileName(java.io.File absFile)
-
locFile2cls
public java.lang.String locFile2cls(java.lang.String locFileName, JavaPath.ClsSrc clsSrc)
-
absFile2cls
public java.lang.String absFile2cls(java.io.File absFile, JavaPath.ClsSrc clsSrc)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
main
public static void main(java.lang.String[] args)
-
-