public byte[] instrumentClass(java.lang.ClassLoader deferTo, String class_name) { if (debug) ; // System.out.println(" getResource <" + class_name + // "> <" + // deferTo.getResource(resourceNameForClassName(class_name)) // + ">"); InputStream s = deferTo.getResourceAsStream(resourceNameForClassName(class_name)); if (s == null) return null; // try to load it // here we might cache modification dates if (debug) ; // System.out.println(indentation + "#" + // (class_name.replace('.', File.separatorChar)) // + ">"); BufferedInputStream stream = new BufferedInputStream(s, 80000); if (stream == null) return null; try { byte[] a = new byte[stream.available()]; stream.read(a); if (debug) ; // System.out.println(" about to instrument <" // + class_name + "> inside <" + this + // "> !! "); a = instrumentBytecodes(a, class_name, deferTo); return a; } catch (IOException e) { e.printStackTrace(); } return null; }
public byte[] bytesForClass(java.lang.ClassLoader deferTo, String class_name) { System.out.println(" bytes for class :" + class_name); InputStream s = deferTo.getResourceAsStream(resourceNameForClassName(class_name)); if (s == null) return null; // try to load it // here we might cache modification dates BufferedInputStream stream = new BufferedInputStream(s, 80000); if (stream == null) return null; try { byte[] a = new byte[stream.available()]; stream.read(a); return a; } catch (IOException e) { e.printStackTrace(); } return null; }
/** * Returns a read-only stream for the contents of the resource specified by {@code resName}. The * mapping between the resource name and the stream is managed by the class' class loader. * * @param resName the name of the resource. * @return a stream for the requested resource or {@code null} if no resource with the specified * name can be found. * @see ClassLoader */ public InputStream getResourceAsStream(String resName) { // Get absolute resource name, but without the leading slash if (resName.startsWith("/")) { resName = resName.substring(1); } else { String pkg = getName(); int dot = pkg.lastIndexOf('.'); if (dot != -1) { pkg = pkg.substring(0, dot).replace('.', '/'); } else { pkg = ""; } resName = pkg + "/" + resName; } // Delegate to proper class loader ClassLoader loader = getClassLoader(); if (loader != null) { return loader.getResourceAsStream(resName); } else { return ClassLoader.getSystemResourceAsStream(resName); } }
public InputStream getResourceAsStream(String resName) { ClassLoader loader = type.getClassLoader(); if (loader == BootstrapClassLoader.getBootstrapClassLoader()) return ClassLoader.getSystemResourceAsStream(toResourceName(resName)); else return loader.getResourceAsStream(toResourceName(resName)); }