Class ClassPath

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class ClassPath
    extends java.lang.Object
    implements java.io.Closeable
    Responsible for loading (class) files from the CLASSPATH. Inspired by sun.tools.ClassPath.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  ClassPath.ClassFile
      Contains information about file/ZIP entry of the Java class.
    • Constructor Summary

      Constructors 
      Constructor Description
      ClassPath()
      Deprecated.
      Use SYSTEM_CLASS_PATH constant
      ClassPath​(java.lang.String classPath)
      Search for classes in given path.
      ClassPath​(ClassPath parent, java.lang.String classPath)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      boolean equals​(java.lang.Object o)  
      byte[] getBytes​(java.lang.String name)  
      byte[] getBytes​(java.lang.String name, java.lang.String suffix)  
      ClassPath.ClassFile getClassFile​(java.lang.String name)  
      ClassPath.ClassFile getClassFile​(java.lang.String name, java.lang.String suffix)  
      static java.lang.String getClassPath()
      Checks for class path components in the following properties: "java.class.path", "sun.boot.class.path", "java.ext.dirs"
      java.io.InputStream getInputStream​(java.lang.String name)  
      java.io.InputStream getInputStream​(java.lang.String name, java.lang.String suffix)
      Return stream for class or resource on CLASSPATH.
      java.lang.String getPath​(java.lang.String name)  
      java.lang.String getPath​(java.lang.String name, java.lang.String suffix)  
      java.net.URL getResource​(java.lang.String name)  
      java.io.InputStream getResourceAsStream​(java.lang.String name)  
      java.util.Enumeration<java.net.URL> getResources​(java.lang.String name)  
      int hashCode()  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

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

      • SYSTEM_CLASS_PATH

        public static final ClassPath SYSTEM_CLASS_PATH
    • Constructor Detail

      • ClassPath

        @Deprecated
        public ClassPath()
        Deprecated.
        Use SYSTEM_CLASS_PATH constant
        Search for classes in CLASSPATH.
      • ClassPath

        public ClassPath​(ClassPath parent,
                         java.lang.String classPath)
      • ClassPath

        public ClassPath​(java.lang.String classPath)
        Search for classes in given path.
        Parameters:
        classPath -
    • Method Detail

      • getClassPath

        public static java.lang.String getClassPath()
        Checks for class path components in the following properties: "java.class.path", "sun.boot.class.path", "java.ext.dirs"
        Returns:
        class path as used by default by BCEL
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • getBytes

        public byte[] getBytes​(java.lang.String name)
                        throws java.io.IOException
        Returns:
        byte array for class
        Throws:
        java.io.IOException
      • getBytes

        public byte[] getBytes​(java.lang.String name,
                               java.lang.String suffix)
                        throws java.io.IOException
        Parameters:
        name - fully qualified file name, e.g. java/lang/String
        suffix - file name ends with suffix, e.g. .java
        Returns:
        byte array for file on class path
        Throws:
        java.io.IOException
      • getClassFile

        public ClassPath.ClassFile getClassFile​(java.lang.String name)
                                         throws java.io.IOException
        Parameters:
        name - fully qualified class name, e.g. java.lang.String
        Returns:
        input stream for class
        Throws:
        java.io.IOException
      • getClassFile

        public ClassPath.ClassFile getClassFile​(java.lang.String name,
                                                java.lang.String suffix)
                                         throws java.io.IOException
        Parameters:
        name - fully qualified file name, e.g. java/lang/String
        suffix - file name ends with suff, e.g. .java
        Returns:
        class file for the java class
        Throws:
        java.io.IOException
      • getInputStream

        public java.io.InputStream getInputStream​(java.lang.String name)
                                           throws java.io.IOException
        Parameters:
        name - fully qualified class name, e.g. java.lang.String
        Returns:
        input stream for class
        Throws:
        java.io.IOException
      • getInputStream

        public java.io.InputStream getInputStream​(java.lang.String name,
                                                  java.lang.String suffix)
                                           throws java.io.IOException
        Return stream for class or resource on CLASSPATH.
        Parameters:
        name - fully qualified file name, e.g. java/lang/String
        suffix - file name ends with suff, e.g. .java
        Returns:
        input stream for file on class path
        Throws:
        java.io.IOException
      • getPath

        public java.lang.String getPath​(java.lang.String name)
                                 throws java.io.IOException
        Parameters:
        name - name of file to search for, e.g. java/lang/String.java
        Returns:
        full (canonical) path for file
        Throws:
        java.io.IOException
      • getPath

        public java.lang.String getPath​(java.lang.String name,
                                        java.lang.String suffix)
                                 throws java.io.IOException
        Parameters:
        name - name of file to search for, e.g. java/lang/String
        suffix - file name suffix, e.g. .java
        Returns:
        full (canonical) path for file, if it exists
        Throws:
        java.io.IOException
      • getResource

        public java.net.URL getResource​(java.lang.String name)
        Parameters:
        name - fully qualified resource name, e.g. java/lang/String.class
        Returns:
        URL supplying the resource, or null if no resource with that name.
        Since:
        6.0
      • getResourceAsStream

        public java.io.InputStream getResourceAsStream​(java.lang.String name)
        Parameters:
        name - fully qualified resource name, e.g. java/lang/String.class
        Returns:
        InputStream supplying the resource, or null if no resource with that name.
        Since:
        6.0
      • getResources

        public java.util.Enumeration<java.net.URL> getResources​(java.lang.String name)
        Parameters:
        name - fully qualified resource name, e.g. java/lang/String.class
        Returns:
        An Enumeration of URLs supplying the resource, or an empty Enumeration if no resource with that name.
        Since:
        6.0
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
        Returns:
        used class path string