Class ClassFileLocator.ForModule

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

    @Enhance
    public static class ClassFileLocator.ForModule
    extends java.lang.Object
    implements ClassFileLocator

    A class file locator that locates class files by querying a Java module's getResourceAsStream method.

    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.

    • Field Detail

      • NO_ARGUMENTS

        private static final java.lang.Object[] NO_ARGUMENTS
        An empty array that can be used to indicate no arguments to avoid an allocation on a reflective call.
      • module

        private final JavaModule module
        The represented Java module.
    • Constructor Detail

      • ForModule

        protected ForModule​(JavaModule module)
        Creates a new class file locator for a Java module.
        Parameters:
        module - The represented Java module.
    • Method Detail

      • ofBootLayer

        public static ClassFileLocator ofBootLayer()
        Returns a class file locator that exposes all class files of the boot module layer. This class file locator is only available on virtual machines of version 9 or later. On earlier versions, the returned class file locator does not locate any resources.
        Returns:
        A class file locator that locates classes of the boot layer.
      • of

        public static ClassFileLocator of​(JavaModule module)
        Returns a class file locator for the provided module. If the provided module is not named, class files are located via this unnamed module's class loader.
        Parameters:
        module - The module to create a class file locator for.
        Returns:
        An appropriate class file locator.
      • locate

        public ClassFileLocator.Resolution locate​(java.lang.String name)
                                           throws java.io.IOException
        Locates the class file for a given type and returns the binary data of the class file.
        Specified by:
        locate in interface ClassFileLocator
        Parameters:
        name - 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.
      • locate

        protected static ClassFileLocator.Resolution locate​(JavaModule module,
                                                            java.lang.String typeName)
                                                     throws java.io.IOException
        Creates a resolution for a Java module's class files.
        Parameters:
        module - The Java module to query.
        typeName - The name of the type being queried.
        Returns:
        A resolution for the query.
        Throws:
        java.io.IOException - If an I/O exception was thrown.
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable