Package javassist

Class LoaderClassPath

  • All Implemented Interfaces:
    ClassPath

    public class LoaderClassPath
    extends java.lang.Object
    implements ClassPath
    A class search-path representing a class loader.

    It is used for obtaining a class file from the given class loader by getResourceAsStream(). The LoaderClassPath refers to the class loader through WeakReference. If the class loader is garbage collected, the other search pathes are examined.

    The given class loader must have both getResourceAsStream() and getResource().

    See Also:
    ClassPool.insertClassPath(ClassPath), ClassPool.appendClassPath(ClassPath), ClassClassPath
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.ref.WeakReference clref  
    • Constructor Summary

      Constructors 
      Constructor Description
      LoaderClassPath​(java.lang.ClassLoader cl)
      Creates a search path representing a class loader.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Closes this class path.
      java.net.URL find​(java.lang.String classname)
      Obtains the URL of the specified class file.
      java.io.InputStream openClassfile​(java.lang.String classname)
      Obtains a class file from the class loader.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

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

      • clref

        private java.lang.ref.WeakReference clref
    • Constructor Detail

      • LoaderClassPath

        public LoaderClassPath​(java.lang.ClassLoader cl)
        Creates a search path representing a class loader.
    • Method Detail

      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • openClassfile

        public java.io.InputStream openClassfile​(java.lang.String classname)
        Obtains a class file from the class loader. This method calls getResourceAsStream(String) on the class loader.
        Specified by:
        openClassfile in interface ClassPath
        Parameters:
        classname - a fully-qualified class name
        Returns:
        the input stream for reading a class file
        See Also:
        Translator
      • find

        public java.net.URL find​(java.lang.String classname)
        Obtains the URL of the specified class file. This method calls getResource(String) on the class loader.
        Specified by:
        find in interface ClassPath
        Parameters:
        classname - a fully-qualified class name.
        Returns:
        null if the class file could not be found.
      • close

        public void close()
        Closes this class path.
        Specified by:
        close in interface ClassPath