Class JavaPath


  • public final class JavaPath
    extends java.lang.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
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static char CLASS_SEP
      Java's class separator . separating classes from their packages and also packages from their subpackages.
      private static char FILE_SEP
      The entry of property file.separator as a char.
      private static java.lang.String INNER_CLASS_SEP
      Java's class separator $ separating inner classes from their enclosing classes.
      private static java.lang.String JAR_END
      File ending .jar identifying jar-files.
      private static int LEN_BUFFER
      The length of a buffer to read at once.
      private static java.lang.String PATH_SEP
      The entry of property path.separator.
      private java.util.List<java.io.File> roots
      The list of entries of this path.
      private static java.lang.String ZIP_END
      File ending .zip identifying zip-files.
    • Constructor Summary

      Constructors 
      Constructor Description
      JavaPath​(java.lang.String path)
      Creates a new JavaPath instance.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String absFile2cls​(java.io.File absFile, JavaPath.ClsSrc clsSrc)  
      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.
      java.io.File getFile​(java.lang.String localFilename)  
      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.
      java.io.InputStream getInputStream​(java.lang.String clsName)  
      java.lang.String getLocFileName​(java.io.File absFile)  
      java.lang.String locFile2cls​(java.lang.String locFileName, JavaPath.ClsSrc clsSrc)  
      private JavaPath.FileWrapper locFile2Wrapper​(java.lang.String localFilename)
      Converts a local file name into the wrapper of the file found on the path.
      static void main​(java.lang.String[] args)  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • FILE_SEP

        private static final char FILE_SEP
        The entry of property file.separator as a char.
      • PATH_SEP

        private static final java.lang.String PATH_SEP
        The entry of property path.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 .zip identifying zip-files.
        See Also:
        Constant Field Values
      • JAR_END

        private static final java.lang.String JAR_END
        File ending .jar identifying 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 new JavaPath instance. Essentially, roots is initialized.
        Parameters:
        path - a path as a String value. 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 of path.
    • 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 a String value.
        clsSrc - a ClsSrc which 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: roots is 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 a String value.
        clsSrc - a ClsSrc which determines whether to convert the class name into a class file or into a source file.
        Returns:
        the source or class File corresponding with the given classname if there is one; otherwise returns null. 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 unless null is 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 a String value.
        Returns:
        a FileWrapper representing the first file found on the path with the appropriate name. If the file is found in a directory of the path, an JavaPath.OrdFileWrapper is returned, if it is found within a zip- or jar-file, a JavaPath.ZipEntryWrapper is 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:
        toString in class java.lang.Object
      • main

        public static void main​(java.lang.String[] args)