1 15 16 package javassist; 17 18 import java.io.*; 19 import java.net.URL ; 20 import java.net.MalformedURLException ; 21 22 48 public class ByteArrayClassPath implements ClassPath { 49 protected String classname; 50 protected byte[] classfile; 51 52 59 public ByteArrayClassPath(String name, byte[] classfile) { 60 this.classname = name; 61 this.classfile = classfile; 62 } 63 64 67 public void close() {} 68 69 public String toString() { 70 return "byte[]:" + classname; 71 } 72 73 76 public InputStream openClassfile(String classname) { 77 if(this.classname.equals(classname)) 78 return new ByteArrayInputStream(classfile); 79 else 80 return null; 81 } 82 83 86 public URL find(String classname) { 87 if(this.classname.equals(classname)) { 88 String cname = classname.replace('.', '/') + ".class"; 89 try { 90 return new URL ("file:/ByteArrayClassPath/" + cname); 92 } 93 catch (MalformedURLException e) {} 94 } 95 96 return null; 97 } 98 } 99 | Popular Tags |