Package eu.simuline.util
Class JavaPath
- java.lang.Object
-
- eu.simuline.util.JavaPath
-
public final class JavaPath extends Object
Represents 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 StringINNER_CLASS_SEPJava's class separator$separating inner classes from their enclosing classes.private static StringJAR_ENDFile ending.jaridentifying jar-files.private static intLEN_BUFFERThe length of a buffer to read at once.private static StringPATH_SEPThe entry of propertypath.separator.private List<File>rootsThe list of entries of this path.private static StringZIP_ENDFile ending.zipidentifying zip-files.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description StringabsFile2cls(File absFile, JavaPath.ClsSrc clsSrc)private Stringcls2locFile(String clsName, JavaPath.ClsSrc clsSrc)Converts a class name into the into the corresponding name of a local source file or class file.FilegetFile(String localFilename)FilegetFile(String clsName, JavaPath.ClsSrc clsSrc)Converts a class name into the corresponding source file or class file if possible.InputStreamgetInputStream(String clsName)StringgetLocFileName(File absFile)StringlocFile2cls(String locFileName, JavaPath.ClsSrc clsSrc)private JavaPath.FileWrapperlocFile2Wrapper(String localFilename)Converts a local file name into the wrapper of the file found on the path.static voidmain(String[] args)StringtoString()
-
-
-
Field Detail
-
FILE_SEP
private static final char FILE_SEP
The entry of propertyfile.separatoras a char.
-
PATH_SEP
private static final 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 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 String ZIP_END
File ending.zipidentifying zip-files.- See Also:
- Constant Field Values
-
JAR_END
private static final 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
-
-
Constructor Detail
-
JavaPath
public JavaPath(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:
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 String cls2locFile(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 File getFile(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.
-
getInputStream
public InputStream getInputStream(String clsName) throws IOException
- Throws:
IOException
-
locFile2Wrapper
private JavaPath.FileWrapper locFile2Wrapper(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.
-
locFile2cls
public String locFile2cls(String locFileName, JavaPath.ClsSrc clsSrc)
-
absFile2cls
public String absFile2cls(File absFile, JavaPath.ClsSrc clsSrc)
-
main
public static void main(String[] args)
-
-