Class ClassFileLocator.ForClassLoader

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

    public static class ClassFileLocator.ForClassLoader
    extends java.lang.Object
    implements ClassFileLocator

    A class file locator that queries a class loader for binary representations of class files.

    Important: Even when calling Closeable.close() on this class file locator, no underlying class loader is closed if it implements the Closeable interface as this is typically not intended.

    • Constructor Detail

      • ForClassLoader

        protected ForClassLoader​(java.lang.ClassLoader classLoader)
        Creates a new class file locator for the given class loader.
        Parameters:
        classLoader - The class loader to query which must not be the bootstrap class loader, i.e. null.
    • Method Detail

      • ofClassPath

        public static ClassFileLocator ofClassPath()
        Creates a class file locator that queries the system class loader.
        Returns:
        A class file locator that queries the system class loader.
      • of

        public static ClassFileLocator of​(java.lang.ClassLoader classLoader)
        Creates a class file locator for a given class loader.
        Parameters:
        classLoader - The class loader to be used. If this class loader represents the bootstrap class loader which is represented by the null value, this system class loader is used instead.
        Returns:
        A corresponding source locator.
      • read

        public static ClassFileLocator.Resolution read​(java.lang.Class<?> type)
        Attempts to create a binary representation of a loaded type by requesting data from its ClassLoader.
        Parameters:
        type - The type of interest.
        Returns:
        The binary data to this type which might be illegal.
      • locate

        public ClassFileLocator.Resolution locate​(java.lang.String typeName)
                                           throws java.io.IOException
        Description copied from interface: ClassFileLocator
        Locates the class file for a given type and returns the binary data of the class file.
        Specified by:
        locate in interface ClassFileLocator
        Parameters:
        typeName - The name of the type to locate a class file representation for.
        Returns:
        Any binary representation of the type which might be illegal.
        Throws:
        java.io.IOException - If reading a class file causes an error.
      • 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
      • locate

        protected static ClassFileLocator.Resolution locate​(java.lang.ClassLoader classLoader,
                                                            java.lang.String typeName)
                                                     throws java.io.IOException
        Locates the class file for the supplied type by requesting a resource from the class loader.
        Parameters:
        classLoader - The class loader to query for the resource.
        typeName - The name of the type for which to locate a class file.
        Returns:
        A resolution for the class file.
        Throws:
        java.io.IOException - If reading the class file causes an exception.