1 |
| package org.jboss.cache.marshall; |
2 |
| |
3 |
| import java.io.ByteArrayOutputStream; |
4 |
| import java.io.IOException; |
5 |
| import java.io.InputStream; |
6 |
| |
7 |
| public class FooClassLoader extends ClassLoader |
8 |
| { |
9 |
| private Class foo; |
10 |
4
| public FooClassLoader(ClassLoader parent)
|
11 |
| { |
12 |
4
| super(parent);
|
13 |
| } |
14 |
| |
15 |
4
| public Class loadFoo() throws ClassNotFoundException
|
16 |
| { |
17 |
4
| if (foo == null)
|
18 |
| { |
19 |
4
| try
|
20 |
| { |
21 |
4
| InputStream is = getResourceAsStream("org/jboss/cache/marshall/Foo.clazz");
|
22 |
4
| byte[] bytes = new byte[1024];
|
23 |
4
| ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
|
24 |
4
| int read;
|
25 |
?
| while ((read = is.read(bytes)) > -1) {
|
26 |
8
| baos.write(bytes, 0, read);
|
27 |
| } |
28 |
4
| bytes = baos.toByteArray();
|
29 |
4
| foo = this.defineClass("org.jboss.cache.marshall.Foo", bytes, 0, bytes.length);
|
30 |
| } |
31 |
| catch (IOException e) |
32 |
| { |
33 |
0
| throw new ClassNotFoundException("cannot read org/jboss/cache/marshall/Foo.clazz", e);
|
34 |
| } |
35 |
| } |
36 |
4
| return foo;
|
37 |
| } |
38 |
| |
39 |
| } |