Package net.bytebuddy.dynamic
Class ClassFileLocator.ForJarFile
java.lang.Object
net.bytebuddy.dynamic.ClassFileLocator.MultiReleaseAware
net.bytebuddy.dynamic.ClassFileLocator.ForJarFile
- All Implemented Interfaces:
Closeable
,AutoCloseable
,ClassFileLocator
- Enclosing interface:
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.Compound, ClassFileLocator.Filtering, ClassFileLocator.ForClassLoader, ClassFileLocator.ForFolder, ClassFileLocator.ForInstrumentation, ClassFileLocator.ForJarFile, ClassFileLocator.ForModule, ClassFileLocator.ForModuleFile, ClassFileLocator.ForUrl, ClassFileLocator.MultiReleaseAware, ClassFileLocator.NoOp, ClassFileLocator.PackageDiscriminating, ClassFileLocator.Resolution, ClassFileLocator.Simple
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final boolean
Indicates if the jar file should be closed upon closing this class file locator.private final JarFile
The jar file to read from.A list of potential locations of the runtime jar for different platforms.Fields inherited from class net.bytebuddy.dynamic.ClassFileLocator.MultiReleaseAware
NO_MULTI_RELEASE
Fields inherited from interface net.bytebuddy.dynamic.ClassFileLocator
CLASS_FILE_EXTENSION, META_INF_VERSIONS
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
ForJarFile
(int[] version, JarFile jarFile, boolean close) Creates a new class file locator for the given jar file.ForJarFile
(JarFile jarFile) Creates a new class file locator for the given jar file. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
protected byte[]
Resolves a possible multi-release entry, if it exists.static ClassFileLocator
Creates a new class file locator for the given jar file.static ClassFileLocator
of
(File file, ClassFileVersion classFileVersion) Creates a new class file locator for the given jar file.static ClassFileLocator
of
(JarFile jarFile, ClassFileVersion classFileVersion) Creates a new class file locator for the given jar file.private static ClassFileLocator
of
(JarFile jarFile, ClassFileVersion classFileVersion, boolean close) Creates a new class file locator for the given jar file.static ClassFileLocator
Resolves a class file locator for the class path that reads class files directly from the file system.static ClassFileLocator
ofClassPath
(String classPath) Resolves a class file locator for the class path that reads class files directly from the file system.static ClassFileLocator
Resolves a class file locator for the runtime jar.Methods inherited from class net.bytebuddy.dynamic.ClassFileLocator.MultiReleaseAware
locate
-
Field Details
-
RUNTIME_LOCATIONS
A list of potential locations of the runtime jar for different platforms. -
jarFile
The jar file to read from. -
close
Indicates if the jar file should be closed upon closing this class file locator.
-
-
Constructor Details
-
ForJarFile
Creates a new class file locator for the given jar file. The jar file will not be closed upon closing this class file locator.- Parameters:
jarFile
- The jar file to read from.
-
ForJarFile
Creates a new class file locator for the given jar file.- Parameters:
version
- Contains the existing multi-release jar folders that are available for the current JVM version in decreasing order.jarFile
- The jar file to read from.close
- Indicates if the jar file should be closed upon closing this class file locator.
-
-
Method Details
-
of
Creates a new class file locator for the given jar file. Multi-release jars are not considered.- 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.
-
of
Creates a new class file locator for the given jar file. Multi-release jar files are resolved as if executed on a JVM of the supplied version.- Parameters:
file
- The jar file to read from.classFileVersion
- The class file version to consider when resolving class files in multi-release jars.- Returns:
- A class file locator for the jar file.
- Throws:
IOException
- If an I/O exception is thrown.
-
of
public static ClassFileLocator of(JarFile jarFile, ClassFileVersion classFileVersion) throws IOException Creates a new class file locator for the given jar file. Multi-release jar files are resolved as if executed on a JVM of the supplied version. The jar file will not be closed upon closing this class file locator.- Parameters:
jarFile
- The jar file to read from.classFileVersion
- The class file version to consider when resolving class files in multi-release jars.- Returns:
- A class file locator for the jar file.
- Throws:
IOException
- If an I/O exception is thrown.
-
of
private static ClassFileLocator of(JarFile jarFile, ClassFileVersion classFileVersion, boolean close) throws IOException Creates a new class file locator for the given jar file. Multi-release jar files are resolved as if executed on a JVM of the supplied version.- Parameters:
jarFile
- The jar file to read from.classFileVersion
- The class file version to consider when resolving class files in multi-release jars.close
- Indicates if the jar file should be closed upon closing this class file locator.- Returns:
- A class file locator for the jar file.
- Throws:
IOException
- If an I/O exception is thrown.
-
ofClassPath
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
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:
IOException
- If an I/O exception occurs.
-
ofRuntimeJar
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.
-
doLocate
Resolves a possible multi-release entry, if it exists.- Specified by:
doLocate
in classClassFileLocator.MultiReleaseAware
- Parameters:
path
- The path of the class file.- Returns:
- The class file's binary representation or
null
if it does not exist. - Throws:
IOException
- If an I/O exception occurs.
-
close
- Throws:
IOException
-