KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > marshall > FooClassLoader


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