49 |
import java.lang.reflect.Constructor; |
import java.lang.reflect.Constructor; |
50 |
import java.net.URL; |
import java.net.URL; |
51 |
import java.net.URLClassLoader; |
import java.net.URLClassLoader; |
52 |
|
import java.nio.ByteBuffer; |
53 |
import java.security.CodeSource; |
import java.security.CodeSource; |
54 |
import java.security.PermissionCollection; |
import java.security.PermissionCollection; |
55 |
import java.security.Policy; |
import java.security.Policy; |
473 |
} |
} |
474 |
|
|
475 |
/** |
/** |
476 |
|
* Helper to define a class using the contents of a byte buffer. If |
477 |
|
* the domain is null, the default of |
478 |
|
* <code>Policy.getPolicy().getPermissions(new CodeSource(null, |
479 |
|
* null))</code> is used. Once a class has been defined in a |
480 |
|
* package, all further classes in that package must have the same |
481 |
|
* set of certificates or a SecurityException is thrown. |
482 |
|
* |
483 |
|
* @param name the name to give the class. null if unknown |
484 |
|
* @param buf a byte buffer containing bytes that form a class. |
485 |
|
* @param domain the ProtectionDomain to give to the class, null for the |
486 |
|
* default protection domain |
487 |
|
* @return the class that was defined |
488 |
|
* @throws ClassFormatError if data is not in proper classfile format |
489 |
|
* @throws NoClassDefFoundError if the supplied name is not the same as |
490 |
|
* the one specified by the byte buffer. |
491 |
|
* @throws SecurityException if name starts with "java.", or if certificates |
492 |
|
* do not match up |
493 |
|
* @since 1.5 |
494 |
|
*/ |
495 |
|
protected final Class defineClass(String name, ByteBuffer buf, |
496 |
|
ProtectionDomain domain) |
497 |
|
throws ClassFormatError |
498 |
|
{ |
499 |
|
byte[] data = new byte[buf.remaining()]; |
500 |
|
buf.get(data); |
501 |
|
return defineClass(name, data, 0, data.length, domain); |
502 |
|
} |
503 |
|
|
504 |
|
/** |
505 |
* Links the class, if that has not already been done. Linking basically |
* Links the class, if that has not already been done. Linking basically |
506 |
* resolves all references to other classes made by this class. |
* resolves all references to other classes made by this class. |
507 |
* |
* |