Class ClassFileLocator.ForModule

java.lang.Object
net.bytebuddy.dynamic.ClassFileLocator.ForModule
All Implemented Interfaces:
Closeable, AutoCloseable, ClassFileLocator
Enclosing interface:
ClassFileLocator

@Enhance public static class ClassFileLocator.ForModule extends 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 Details

    • NO_ARGUMENT

      private static final Object[] NO_ARGUMENT
      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 Details

    • ForModule

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

    • 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(String name) throws 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:
      IOException - If reading a class file causes an error.
    • locate

      protected static ClassFileLocator.Resolution locate(JavaModule module, String typeName) throws 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:
      IOException - If an I/O exception was thrown.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable