Package net.bytebuddy.dynamic
Class ClassFileLocator.ForJarFile
- java.lang.Object
-
- net.bytebuddy.dynamic.ClassFileLocator.ForJarFile
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,ClassFileLocator
- Enclosing interface:
- ClassFileLocator
@Enhance public static class ClassFileLocator.ForJarFile extends java.lang.Object implements ClassFileLocator
A class file locator that locates classes within a Java jar file.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface net.bytebuddy.dynamic.ClassFileLocator
ClassFileLocator.AgentBased, ClassFileLocator.Compound, ClassFileLocator.ForClassLoader, ClassFileLocator.ForFolder, ClassFileLocator.ForJarFile, ClassFileLocator.ForModule, ClassFileLocator.ForModuleFile, ClassFileLocator.ForUrl, ClassFileLocator.NoOp, ClassFileLocator.PackageDiscriminating, ClassFileLocator.Resolution, ClassFileLocator.Simple
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.jar.JarFile
jarFile
The jar file to read from.private static java.util.List<java.lang.String>
RUNTIME_LOCATIONS
A list of potential locations of the runtime jar for different platforms.-
Fields inherited from interface net.bytebuddy.dynamic.ClassFileLocator
CLASS_FILE_EXTENSION
-
-
Constructor Summary
Constructors Constructor Description ForJarFile(java.util.jar.JarFile jarFile)
Creates a new class file locator for the given jar file.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
ClassFileLocator.Resolution
locate(java.lang.String name)
Locates the class file for a given type and returns the binary data of the class file.static ClassFileLocator
of(java.io.File file)
Creates a new class file locator for the given jar file.static ClassFileLocator
ofClassPath()
Resolves a class file locator for the class path that reads class files directly from the file system.static ClassFileLocator
ofClassPath(java.lang.String classPath)
Resolves a class file locator for the class path that reads class files directly from the file system.static ClassFileLocator
ofRuntimeJar()
Resolves a class file locator for the runtime jar.
-
-
-
Method Detail
-
of
public static ClassFileLocator of(java.io.File file) throws java.io.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:
java.io.IOException
- If an I/O exception is thrown.
-
ofClassPath
public static ClassFileLocator ofClassPath() throws java.io.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:
java.io.IOException
- If an I/O exception occurs.
-
ofClassPath
public static ClassFileLocator ofClassPath(java.lang.String classPath) throws java.io.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 bypath.separator
.- Returns:
- A class file locator for the class path.
- Throws:
java.io.IOException
- If an I/O exception occurs.
-
ofRuntimeJar
public static ClassFileLocator ofRuntimeJar() throws java.io.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:
java.io.IOException
- If an I/O exception occurs.
-
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 interfaceClassFileLocator
- 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.
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
-