diff options
| author | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2005-09-21 22:35:31 +0000 |
|---|---|---|
| committer | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2005-09-21 22:35:31 +0000 |
| commit | bd023ae78e799e3ed240c5d55bab92e8b993f284 (patch) | |
| tree | f986ed77c5acb7e70255b5fe4f8bb1c633fbb424 /java/lang | |
| parent | c71d58e031a4eaf560ad852ddafae37bf4a20bd6 (diff) | |
| download | classpath-bd023ae78e799e3ed240c5d55bab92e8b993f284.tar.gz | |
2004-10-09 Tom Tromey <tromey@redhat.com>
* java/lang/ClassLoader.java
(defineClass(String,ByteBuffer,ProtectionDomain)): New method.
Diffstat (limited to 'java/lang')
| -rw-r--r-- | java/lang/ClassLoader.java | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/java/lang/ClassLoader.java b/java/lang/ClassLoader.java index 031a8ed66..9f586c4cf 100644 --- a/java/lang/ClassLoader.java +++ b/java/lang/ClassLoader.java @@ -49,6 +49,7 @@ import java.io.InputStream; import java.lang.reflect.Constructor; import java.net.URL; import java.net.URLClassLoader; +import java.nio.ByteBuffer; import java.security.CodeSource; import java.security.PermissionCollection; import java.security.Policy; @@ -472,6 +473,35 @@ public abstract class ClassLoader } /** + * Helper to define a class using the contents of a byte buffer. If + * the domain is null, the default of + * <code>Policy.getPolicy().getPermissions(new CodeSource(null, + * null))</code> is used. Once a class has been defined in a + * package, all further classes in that package must have the same + * set of certificates or a SecurityException is thrown. + * + * @param name the name to give the class. null if unknown + * @param buf a byte buffer containing bytes that form a class. + * @param domain the ProtectionDomain to give to the class, null for the + * default protection domain + * @return the class that was defined + * @throws ClassFormatError if data is not in proper classfile format + * @throws NoClassDefFoundError if the supplied name is not the same as + * the one specified by the byte buffer. + * @throws SecurityException if name starts with "java.", or if certificates + * do not match up + * @since 1.5 + */ + protected final Class defineClass(String name, ByteBuffer buf, + ProtectionDomain domain) + throws ClassFormatError + { + byte[] data = new byte[buf.remaining()]; + buf.get(data); + return defineClass(name, data, 0, data.length, domain); + } + + /** * Links the class, if that has not already been done. Linking basically * resolves all references to other classes made by this class. * |
