Class ClassFileLocator.ForJarFile

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

@Enhance public static class ClassFileLocator.ForJarFile extends Object implements ClassFileLocator
A class file locator that locates classes within a Java jar file.
  • Field Details

    • RUNTIME_LOCATIONS

      private static final List<String> RUNTIME_LOCATIONS
      A list of potential locations of the runtime jar for different platforms.
    • jarFile

      private final JarFile jarFile
      The jar file to read from.
  • Constructor Details

    • ForJarFile

      public ForJarFile(JarFile jarFile)
      Creates a new class file locator for the given jar file.
      Parameters:
      jarFile - The jar file to read from.
  • Method Details

    • of

      public static ClassFileLocator of(File file) throws IOException
      Creates a new class file locator for the given jar file.
      Parameters:
      file - The jar file to read from.
      Returns:
      A class file locator for the jar file.
      Throws:
      IOException - If an I/O exception is thrown.
    • ofClassPath

      public static ClassFileLocator ofClassPath() throws IOException
      Resolves a class file locator for the class path that reads class files directly from the file system. The resulting class file locator does not imply classes on the boot path.
      Returns:
      A class file locator for the class path.
      Throws:
      IOException - If an I/O exception occurs.
    • ofClassPath

      public static ClassFileLocator ofClassPath(String classPath) throws IOException

      Resolves a class file locator for the class path that reads class files directly from the file system.

      Note: The resulting class file locator does not include classes of the bootstrap class loader.

      Parameters:
      classPath - The class path to scan with the elements separated by path.separator.
      Returns:
      A class file locator for the class path.
      Throws:
      IOException - If an I/O exception occurs.
    • ofRuntimeJar

      public static ClassFileLocator ofRuntimeJar() throws IOException
      Resolves a class file locator for the runtime jar. If such a file does not exist or cannot be located, a runtime exception is thrown.
      Returns:
      A class file locator for the runtime jar, if available.
      Throws:
      IOException - If an I/O exception occurs.
    • 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.
    • close

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