Class BytecodeWithUrl
java.lang.Object
io.opentelemetry.javaagent.tooling.BytecodeWithUrl
Provides the bytecode and the original resource URL for loaded and not-yet loaded classes. The
implementation is based on
ClassFileLocator.ForClassLoader, with
the difference that it preserves the original classfile resource URL. In addition BytecodeWithUrl created can be generated for runtime generated types, this class will take care
of runtime generating URLs for those.-
Method Summary
Modifier and TypeMethodDescriptionabstract BytecodeWithUrlcached()Creates a cached copy of thisBytecodeWithUrl.static BytecodeWithUrlSame ascreate(String, ClassLoader), but easier to use for already loaded classes.static BytecodeWithUrlCreates aBytecodeWithUrlfor a runtime-generated type.static BytecodeWithUrlcreate(String className, ClassLoader classLoader) Creates aBytecodeWithUrlfor the class with the provided fully qualified name.static BytecodeWithUrlcreate(net.bytebuddy.dynamic.DynamicType.Unloaded<?> dynamicType) Invokescreate(String, byte[])for the provided dynamic type.abstract byte[]Provides the bytecode of the class.abstract URLgetUrl()Provides a URL pointing to the specific classfile.
-
Method Details
-
getUrl
Provides a URL pointing to the specific classfile.- Returns:
- the URL
-
getBytecode
public abstract byte[] getBytecode()Provides the bytecode of the class. The result is the same as callingURL.openStream()ongetUrl()and draining that stream.- Returns:
- the bytecode of the class.
-
cached
Creates a cached copy of thisBytecodeWithUrl. The cached copy eagerly loads the bytecode, so thatgetBytecode()is guaranteed to not cause any IO. This comes at the cost of a higher heap consumption, as the bytecode is kept in memory.- Returns:
- an ClassFileSource implementing the described caching behaviour.
-
create
Creates aBytecodeWithUrlfor the class with the provided fully qualified name. The .class file for the provided classname must be available as a resource in the provided classloader. The class is guaranteed to not be loaded during this process.- Parameters:
className- the fully qualified name of the class to copyclassLoader- the classloader- Returns:
- the ClassCopySource which can be used to copy the provided class to other classloaders.
-
create
Same ascreate(String, ClassLoader), but easier to use for already loaded classes.- Parameters:
loadedClass- the class to copy- Returns:
- the ClassCopySource which can be used to copy the provided class to other classloaders.
-
create
Creates aBytecodeWithUrlfor a runtime-generated type. It will also provide an artificially generatedURLpointing to the in-memory bytecode.- Parameters:
className- the name of the class represented by the provided bytecodebytecode- the bytecode of the class- Returns:
- the
BytecodeWithUrlreferring to this dynamically generated class
-
create
Invokescreate(String, byte[])for the provided dynamic type.- Parameters:
dynamicType- the type to generate theBytecodeWithUrl- Returns:
- the
BytecodeWithUrlreferring to this dynamically generated type
-