ClassLoader.DefineClass Method

Definition

Overloads

DefineClass(Byte[], Int32, Int32)
Obsolete.

Converts an array of bytes into an instance of class Class.

DefineClass(String, ByteBuffer, ProtectionDomain)

Converts a java.nio.ByteBuffer ByteBuffer into an instance of class Class, with the given ProtectionDomain.

DefineClass(String, Byte[], Int32, Int32)

Converts an array of bytes into an instance of class Class.

DefineClass(String, Byte[], Int32, Int32, ProtectionDomain)

Converts an array of bytes into an instance of class Class, with a given ProtectionDomain.

DefineClass(Byte[], Int32, Int32)

Caution

deprecated

Converts an array of bytes into an instance of class Class.

[Android.Runtime.Register("defineClass", "([BII)Ljava/lang/Class;", "")]
[System.Obsolete("deprecated")]
protected Java.Lang.Class? DefineClass (byte[]? b, int off, int len);
[<Android.Runtime.Register("defineClass", "([BII)Ljava/lang/Class;", "")>]
[<System.Obsolete("deprecated")>]
member this.DefineClass : byte[] * int * int -> Java.Lang.Class

Parameters

b
Byte[]

The bytes that make up the class data. The bytes in positions off through off+len-1 should have the format of a valid class file as defined by <cite>The Java Virtual Machine Specification</cite>.

off
Int32

The start offset in b of the class data

len
Int32

The length of the class data

Returns

The Class object that was created from the specified class data

Attributes

Exceptions

if classRep does not contain a valid class.

if offset , length or if offset + length is greater than the length of classRep.

Remarks

Converts an array of bytes into an instance of class Class. Before the Class can be used it must be resolved. This method is deprecated in favor of the version that takes a binary name as its first argument, and is more secure.

This member is deprecated. Replaced by #defineClass(String, byte[], int, int) defineClass(String, byte[], int, int)

Java documentation for java.lang.ClassLoader.defineClass(byte[], int, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

DefineClass(String, ByteBuffer, ProtectionDomain)

Converts a java.nio.ByteBuffer ByteBuffer into an instance of class Class, with the given ProtectionDomain.

[Android.Runtime.Register("defineClass", "(Ljava/lang/String;Ljava/nio/ByteBuffer;Ljava/security/ProtectionDomain;)Ljava/lang/Class;", "")]
protected Java.Lang.Class? DefineClass (string? name, Java.Nio.ByteBuffer? b, Java.Security.ProtectionDomain? protectionDomain);
[<Android.Runtime.Register("defineClass", "(Ljava/lang/String;Ljava/nio/ByteBuffer;Ljava/security/ProtectionDomain;)Ljava/lang/Class;", "")>]
member this.DefineClass : string * Java.Nio.ByteBuffer * Java.Security.ProtectionDomain -> Java.Lang.Class

Parameters

name
String

The expected binary name. of the class, or null if not known

b
ByteBuffer

The bytes that make up the class data. The bytes from positions b.position() through b.position() + b.limit() -1 should have the format of a valid class file as defined by <cite>The Java Virtual Machine Specification</cite>.

protectionDomain
ProtectionDomain

The ProtectionDomain of the class, or null.

Returns

The Class object created from the data, and ProtectionDomain.

Attributes

Exceptions

if b does not contain a valid class.

if className is not equal to the name of the class contained in b.

Remarks

Converts a java.nio.ByteBuffer ByteBuffer into an instance of class Class, with the given ProtectionDomain. If the given ProtectionDomain is null, then a default protection domain will be assigned to the class as specified in the documentation for #defineClass(String, byte[], int, int). Before the class can be used it must be resolved.

The rules about the first class defined in a package determining the set of certificates for the package, the restrictions on class names, and the defined package of the class are identical to those specified in the documentation for #defineClass(String, byte[], int, int, ProtectionDomain).

An invocation of this method of the form cl.defineClass(name,bBuffer,pd) yields exactly the same result as the statements

...<br> byte[] temp = new byte[bBuffer.{@link java.nio.ByteBuffer#remaining remaining}()];<br> bBuffer.{@link java.nio.ByteBuffer#get(byte[]) get}(temp);<br> return {@link #defineClass(String, byte[], int, int, ProtectionDomain) cl.defineClass}(name, temp, 0, temp.length, pd);<br>

Added in 1.5.

Java documentation for java.lang.ClassLoader.defineClass(java.lang.String, java.nio.ByteBuffer, java.security.ProtectionDomain).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

DefineClass(String, Byte[], Int32, Int32)

Converts an array of bytes into an instance of class Class.

[Android.Runtime.Register("defineClass", "(Ljava/lang/String;[BII)Ljava/lang/Class;", "")]
protected Java.Lang.Class? DefineClass (string? name, byte[]? b, int off, int len);
[<Android.Runtime.Register("defineClass", "(Ljava/lang/String;[BII)Ljava/lang/Class;", "")>]
member this.DefineClass : string * byte[] * int * int -> Java.Lang.Class

Parameters

name
String

The expected binary name of the class, or null if not known

b
Byte[]

The bytes that make up the class data. The bytes in positions off through off+len-1 should have the format of a valid class file as defined by <cite>The Java Virtual Machine Specification</cite>.

off
Int32

The start offset in b of the class data

len
Int32

The length of the class data

Returns

The Class object that was created from the specified class data.

Attributes

Exceptions

if classRep does not contain a valid class.

if offset , length or if offset + length is greater than the length of classRep.

Remarks

Converts an array of bytes into an instance of class Class. Before the Class can be used it must be resolved.

This method assigns a default java.security.ProtectionDomain ProtectionDomain to the newly defined class. The ProtectionDomain is effectively granted the same set of permissions returned when java.security.Policy#getPermissions(java.security.CodeSource) Policy.getPolicy().getPermissions(new CodeSource(null, null)) is invoked. The default protection domain is created on the first invocation of #defineClass(String, byte[], int, int) defineClass, and re-used on subsequent invocations.

To assign a specific ProtectionDomain to the class, use the #defineClass(String, byte[], int, int, java.security.ProtectionDomain) defineClass method that takes a ProtectionDomain as one of its arguments.

This method defines a package in this class loader corresponding to the package of the Class (if such a package has not already been defined in this class loader). The name of the defined package is derived from the binary name of the class specified by the byte array b. Other properties of the defined package are as specified by Package.

Added in 1.1.

Java documentation for java.lang.ClassLoader.defineClass(java.lang.String, byte[], int, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

DefineClass(String, Byte[], Int32, Int32, ProtectionDomain)

Converts an array of bytes into an instance of class Class, with a given ProtectionDomain.

[Android.Runtime.Register("defineClass", "(Ljava/lang/String;[BIILjava/security/ProtectionDomain;)Ljava/lang/Class;", "")]
protected Java.Lang.Class? DefineClass (string? name, byte[]? b, int off, int len, Java.Security.ProtectionDomain? protectionDomain);
[<Android.Runtime.Register("defineClass", "(Ljava/lang/String;[BIILjava/security/ProtectionDomain;)Ljava/lang/Class;", "")>]
member this.DefineClass : string * byte[] * int * int * Java.Security.ProtectionDomain -> Java.Lang.Class

Parameters

name
String

The expected binary name of the class, or null if not known

b
Byte[]

The bytes that make up the class data. The bytes in positions off through off+len-1 should have the format of a valid class file as defined by <cite>The Java Virtual Machine Specification</cite>.

off
Int32

The start offset in b of the class data

len
Int32

The length of the class data

protectionDomain
ProtectionDomain

The ProtectionDomain of the class

Returns

The Class object created from the data, and ProtectionDomain.

Attributes

Exceptions

if classRep does not contain a valid class.

if offset , length or if offset + length is greater than the length of classRep.

if className is not equal to the name of the class contained in classRep.

Remarks

Converts an array of bytes into an instance of class Class, with a given ProtectionDomain.

If the given ProtectionDomain is null, then a default protection domain will be assigned to the class as specified in the documentation for #defineClass(String, byte[], int, int). Before the class can be used it must be resolved.

The first class defined in a package determines the exact set of certificates that all subsequent classes defined in that package must contain. The set of certificates for a class is obtained from the java.security.CodeSource CodeSource within the ProtectionDomain of the class. Any classes added to that package must contain the same set of certificates or a SecurityException will be thrown. Note that if name is null, this check is not performed. You should always pass in the binary name of the class you are defining as well as the bytes. This ensures that the class you are defining is indeed the class you think it is.

This method defines a package in this class loader corresponding to the package of the Class (if such a package has not already been defined in this class loader). The name of the defined package is derived from the binary name of the class specified by the byte array b. Other properties of the defined package are as specified by Package.

Java documentation for java.lang.ClassLoader.defineClass(java.lang.String, byte[], int, int, java.security.ProtectionDomain).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to