1 19 20 package com.sslexplorer.applications.server; 21 22 import java.util.Hashtable ; 23 24 public class ByteArrayClassLoader 25 extends ClassLoader { 26 27 static ByteArrayClassLoader instance; 28 29 Hashtable classes = new Hashtable (); 30 ClassLoader parent; 31 32 public ByteArrayClassLoader(ClassLoader parent) { 33 this.parent = parent; 34 } 35 36 public Class createFromByteArray(String name, byte[] buf, int off, int len) { 37 38 if(!classes.containsKey(name)) { 39 classes.put(name, defineClass(name, buf, off, len)); 40 } 41 return (Class ) classes.get(name); 42 43 } 44 45 public Class loadClass(String name, boolean resolve) throws ClassNotFoundException { 46 47 if(classes.containsKey(name)) { 48 return (Class ) classes.get(name); 49 } else 50 return parent.loadClass(name); 51 } 52 53 public static ByteArrayClassLoader getInstance() { return instance==null? instance = new ByteArrayClassLoader(ByteArrayClassLoader.class.getClassLoader()) : instance; } 54 } 55 | Popular Tags |