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 public FooClassLoader(ClassLoader parent) 11 { 12 super(parent); 13 } 14 15 public Class loadFoo() throws ClassNotFoundException 16 { 17 if (foo == null) 18 { 19 try 20 { 21 InputStream is = getResourceAsStream("org/jboss/cache/marshall/Foo.clazz"); 22 byte[] bytes = new byte[1024]; 23 ByteArrayOutputStream baos = new ByteArrayOutputStream (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 e) 32 { 33 throw new ClassNotFoundException ("cannot read org/jboss/cache/marshall/Foo.clazz", e); 34 } 35 } 36 return foo; 37 } 38 39 } 40 | Popular Tags |