Top Description Inners Fields Constructors Methods
net.bytebuddy.dynamic.loading

public Class ByteArrayClassLoader

extends InjectionClassLoader
Class Inheritance
Known Direct Subclasses
net.bytebuddy.dynamic.loading.ByteArrayClassLoader.ChildFirst
Imports
edu.umd.cs.findbugs.annotations.SuppressFBWarnings, net.bytebuddy.ClassFileVersion, net.bytebuddy.build.AccessControllerPlugin, .HashCodeAndEqualsPlugin, net.bytebuddy.description.type.TypeDescription, net.bytebuddy.utility.GraalImageCode, .JavaModule, net.bytebuddy.utility.dispatcher.JavaDispatcher, net.bytebuddy.utility.nullability.AlwaysNull, .MaybeNull, java.io.ByteArrayInputStream, .IOException, .InputStream, .UnsupportedEncodingException, java.lang.reflect.InvocationTargetException, .Method, java.net.*, java.security.PrivilegedAction, .ProtectionDomain, java.util.*, java.util.concurrent.ConcurrentHashMap, .ConcurrentMap

A java.lang.ClassLoader that is capable of loading explicitly defined classes. The class loader will free any binary resources once a class that is defined by its binary data is loaded. This class loader is thread safe since the class loading mechanics are only called from synchronized context.

Note

Instances of this class loader return URLs for their represented class loaders with the bytebuddy schema. These URLs do not represent URIs as two classes with the same name yield identical URLs but might represents different byte arrays.

Note

Any class and package definition is performed using the creator's java.security.AccessControlContext.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
ByteArrayClassLoader.ChildFirst

A net.bytebuddy.dynamic.loading.ByteArrayClassLoader which applies child-first semantics for the given type definitions.

protected class
ByteArrayClassLoader.ClassDefinitionAction

An action for defining a located class that is not yet loaded.

protected static enum
ByteArrayClassLoader.EmptyEnumeration

An enumeration without any elements.

protected static interface
ByteArrayClassLoader.PackageLookupStrategy

A package lookup strategy for locating a package by name.

public static enum
ByteArrayClassLoader.PersistenceHandler

A persistence handler decides on whether the byte array that represents a loaded class is exposed by the java.lang.ClassLoader#getResourceAsStream(String) method.

protected static class
ByteArrayClassLoader.SingletonEnumeration

An enumeration that contains a single element.

protected static interface
ByteArrayClassLoader.SynchronizationStrategy

An engine for receiving a class loading lock when loading a class.

Field Summary

Modifier and TypeField and Description
protected final Object
accessControlContext

The access control context to use for loading classes or null if this is not supported on the current VM.

protected final ClassFilePostProcessor
classFilePostProcessor

The class file transformer to apply on loaded classes.

private static final int
FROM_BEGINNING

Indicates that an array should be included from its first index.

private static final URL
NO_URL

Indicates that a URL does not exist to improve code readability.

private static final ByteArrayClassLoader.PackageLookupStrategy
PACKAGE_LOOKUP_STRATEGY

A strategy for locating a package by name.

protected final PackageDefinitionStrategy
packageDefinitionStrategy

The package definer to be queried for package definitions.

protected final ByteArrayClassLoader.PersistenceHandler
persistenceHandler

The persistence handler of this class loader.

protected final ProtectionDomain
protectionDomain

The protection domain to apply.

protected static final ByteArrayClassLoader.SynchronizationStrategy.Initializable
SYNCHRONIZATION_STRATEGY

The synchronization engine for the executing JVM.

protected final ConcurrentMap<String, byte[]>
typeDefinitions

A mutable map of type names mapped to their binary representation.

public static final String
URL_SCHEMA

The schema for URLs that represent a class file of byte array class loaders.

Constructor Summary

AccessConstructor and Description
public
ByteArrayClassLoader(ClassLoader
The java.lang.ClassLoader that is the parent of this class loader.
parent
,
Map<String, byte[]>
A map of fully qualified class names pointing to their binary representations.
typeDefinitions
)

Creates a new class loader for a given definition of classes.

public
ByteArrayClassLoader(ClassLoader
The java.lang.ClassLoader that is the parent of this class loader.
parent
,
boolean
true if this class loader is sealed.
sealed
,
Map<String, byte[]>
A map of fully qualified class names pointing to their binary representations.
typeDefinitions
)

Creates a new class loader for a given definition of classes.

public
ByteArrayClassLoader(ClassLoader
The java.lang.ClassLoader that is the parent of this class loader.
parent
,
Map<String, byte[]>
A map of fully qualified class names pointing to their binary representations.
typeDefinitions
,
ByteArrayClassLoader.PersistenceHandler
The persistence handler of this class loader.
persistenceHandler
)

Creates a new class loader for a given definition of classes.

public
ByteArrayClassLoader(ClassLoader
The java.lang.ClassLoader that is the parent of this class loader.
parent
,
boolean
true if this class loader is sealed.
sealed
,
Map<String, byte[]>
A map of fully qualified class names pointing to their binary representations.
typeDefinitions
,
ByteArrayClassLoader.PersistenceHandler
The persistence handler of this class loader.
persistenceHandler
)

Creates a new class loader for a given definition of classes.

public
ByteArrayClassLoader(ClassLoader
The java.lang.ClassLoader that is the parent of this class loader.
parent
,
Map<String, byte[]>
A map of fully qualified class names pointing to their binary representations.
typeDefinitions
,
ProtectionDomain
The protection domain to apply where null references an implicit protection domain.
protectionDomain
,
ByteArrayClassLoader.PersistenceHandler
The persistence handler of this class loader.
persistenceHandler
,
PackageDefinitionStrategy
The package definer to be queried for package definitions.
packageDefinitionStrategy
)

Creates a new class loader for a given definition of classes.

public
ByteArrayClassLoader(ClassLoader
The java.lang.ClassLoader that is the parent of this class loader.
parent
,
boolean
true if this class loader is sealed.
sealed
,
Map<String, byte[]>
A map of fully qualified class names pointing to their binary representations.
typeDefinitions
,
ProtectionDomain
The protection domain to apply where null references an implicit protection domain.
protectionDomain
,
ByteArrayClassLoader.PersistenceHandler
The persistence handler of this class loader.
persistenceHandler
,
PackageDefinitionStrategy
The package definer to be queried for package definitions.
packageDefinitionStrategy
)

Creates a new class loader for a given definition of classes.

public
ByteArrayClassLoader(ClassLoader
The java.lang.ClassLoader that is the parent of this class loader.
parent
,
Map<String, byte[]>
A map of fully qualified class names pointing to their binary representations.
typeDefinitions
,
ProtectionDomain
The protection domain to apply where null references an implicit protection domain.
protectionDomain
,
ByteArrayClassLoader.PersistenceHandler
The persistence handler of this class loader.
persistenceHandler
,
PackageDefinitionStrategy
The package definer to be queried for package definitions.
packageDefinitionStrategy
,
ClassFilePostProcessor
A post processor for class files to apply p
classFilePostProcessor
)

Creates a new class loader for a given definition of classes.

public
ByteArrayClassLoader(ClassLoader
The java.lang.ClassLoader that is the parent of this class loader.
parent
,
boolean
true if this class loader is sealed.
sealed
,
Map<String, byte[]>
A map of fully qualified class names pointing to their binary representations.
typeDefinitions
,
ProtectionDomain
The protection domain to apply where null references an implicit protection domain.
protectionDomain
,
ByteArrayClassLoader.PersistenceHandler
The persistence handler of this class loader.
persistenceHandler
,
PackageDefinitionStrategy
The package definer to be queried for package definitions.
packageDefinitionStrategy
,
ClassFilePostProcessor
A post processor for class files to apply p
classFilePostProcessor
)

Creates a new class loader for a given definition of classes.

Method Summary

Modifier and TypeMethod and Description
protected Map<String, Class<?>>
doDefineClasses(Map<String, byte[]>
The types binary representations.
typeDefinitions
)

Implements abstract net.bytebuddy.dynamic.loading.InjectionClassLoader.doDefineClasses.

Defines a group of types to be loaded by this class loader.
private Package

Returns:

A suitable package or null if no such package exists.
doGetPackage
(String
The name of the package.
name
)

Returns the package for a given name.

private static <
The type of the action's resolved value.
T
>
T

Returns:

The action's resolved value.
doPrivileged
(PrivilegedAction<T>
The action to execute from a privileged context.
action
)

A proxy for java.security.AccessController#doPrivileged that is activated if available.

private static <
The type of the action's resolved value.
T
>
T

Returns:

The action's resolved value.
doPrivileged
(PrivilegedAction<T>
The action to execute from a privileged context.
action
,
Object
The access control context or null if the current VM does not support it.
context
)

A proxy for java.security.AccessController#doPrivileged that is activated if available.

private static void
protected Class<?>
findClass(String
The binary name of the class
name
)

Overrides java.lang.ClassLoader.findClass.

Finds the class with the specified binary name.
protected URL
findResource(String
The resource name
name
)

Overrides java.lang.ClassLoader.findResource.

Finds the resource with the given name.
protected Enumeration<URL>
findResources(String
The resource name
name
)

Overrides java.lang.ClassLoader.findResources.

Returns an enumeration of URL objects representing all the resources with the given name.
private static Object

Returns:

The current access control context or null if the current VM does not support it.
getContext
()

A proxy for java.security.AccessController#getContext that is activated if available.

public static Map<TypeDescription, Class<?>>

Returns:

A map of the given type descriptions pointing to their loaded representations.
load
(ClassLoader
The parent class loader.
classLoader
,
Map<TypeDescription, byte[]>
The unloaded types to be loaded.
types
)

Loads a given set of class descriptions and their binary representations.

public static Map<TypeDescription, Class<?>>

Returns:

A map of the given type descriptions pointing to their loaded representations.
load
(ClassLoader
The parent class loader.
classLoader
,
Map<TypeDescription, byte[]>
The unloaded types to be loaded.
types
,
ProtectionDomain
The protection domain to apply where null references an implicit protection domain.
protectionDomain
,
ByteArrayClassLoader.PersistenceHandler
The persistence handler of the created class loader.
persistenceHandler
,
PackageDefinitionStrategy
The package definer to be queried for package definitions.
packageDefinitionStrategy
,
boolean
true if the class loading should throw an exception if a class was already loaded by a parent class loader.
forbidExisting
,
boolean
true if the class loader should be sealed.
sealed
)

Loads a given set of class descriptions and their binary representations.

private static Object

Returns:

A method handle for this class.
methodHandle
()

Resolves a method handle in the scope of the ByteArrayClassLoader class.

Inherited from net.bytebuddy.dynamic.loading.InjectionClassLoader:
defineClassdefineClassesisSealedseal