1 22 package org.jboss.util.stream; 23 24 import java.io.InputStream ; 25 import java.io.IOException ; 26 import java.io.ObjectInputStream ; 27 import java.io.ObjectStreamClass ; 28 29 import java.lang.reflect.Proxy ; 30 31 45 public class CustomObjectInputStreamWithClassloader 46 extends ObjectInputStream 47 { 48 49 53 ClassLoader cl; 54 55 61 public CustomObjectInputStreamWithClassloader(InputStream in, 62 ClassLoader cl) 63 throws IOException 64 { 65 super(in); 66 this.cl = cl; 67 } 68 69 74 protected ObjectStreamClass readClassDescriptor() 75 throws IOException , ClassNotFoundException 76 { 77 return ObjectStreamClass.lookup(cl.loadClass(readUTF())); 78 } 79 80 91 protected Class resolveClass(ObjectStreamClass classdesc) 92 throws IOException , ClassNotFoundException 93 { 94 return cl.loadClass(classdesc.getName()); 95 } 96 97 106 protected Class resolveProxyClass(String [] interfaces) 107 throws IOException , ClassNotFoundException 108 { 109 110 Class [] interfacesClass = new Class [interfaces.length]; 111 for( int i=0; i< interfaces.length; i++ ) { 112 interfacesClass[i] = Class.forName(interfaces[i], false, cl); 113 } 114 return Proxy.getProxyClass(cl, interfacesClass); 115 } 116 } 117 | Popular Tags |