1 3 import java.io.*; 4 import java.util.Hashtable ; 5 6 public class RodentClassLoader extends ClassLoader { 7 8 public synchronized Class loadClass(String typeName, boolean resolveIt) 9 throws ClassNotFoundException { 10 11 Class result = findLoadedClass(typeName); 14 15 if (result != null) { 16 return result; 18 } 19 20 try { 22 result = super.findSystemClass(typeName); 23 return result; 25 } 26 catch (ClassNotFoundException e) { 27 } 28 29 if (typeName.startsWith("java.")) { 32 throw new ClassNotFoundException (); 33 } 34 35 byte typeData[] = getTypeFromHole(typeName); 37 if (typeData == null) { 38 throw new ClassNotFoundException (); 39 } 40 41 result = defineClass(typeName, typeData, 0, typeData.length); 43 if (result == null) { 44 throw new ClassFormatError (); 45 } 46 47 if (resolveIt) { 48 resolveClass(result); 49 } 50 51 return result; 53 } 54 55 private byte[] getTypeFromHole(String typeName) { 56 57 FileInputStream fis; 58 String fileName = 59 "hole" + File.separatorChar + 60 typeName.replace('.', File.separatorChar) + ".class"; 61 62 try { 63 fis = new FileInputStream(fileName); 64 } 65 catch (FileNotFoundException e) { 66 return null; 67 } 68 69 BufferedInputStream bis = new BufferedInputStream(fis); 70 ByteArrayOutputStream out = new ByteArrayOutputStream(); 71 72 try { 73 int c = bis.read(); 74 while (c != -1) { 75 out.write(c); 76 c = bis.read(); 77 } 78 } 79 catch (IOException e) { 80 return null; 81 } 82 return out.toByteArray(); 83 } 84 } 85 86 | Popular Tags |