/* * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/** * Use this property to verify that the desired classloading is happening.
*/ privatefinalboolean verbose = Boolean.getBoolean("bogoloader.verbose"); /** * Use this property to disable replacement for testing purposes.
*/ privatefinalboolean noReplace = Boolean.getBoolean("bogoloader.noreplace");
/** * Set of class names that should be loaded with this loader. * Others are loaded with the system class loader, except for those * that are transformed.
*/ private Set<String> nonSystem;
/** * Map from class names to a bytecode transformer factory.
*/ private Map<String, VisitorMaker> replaced;
/** * Keep track (not terribly efficiently) of which classes have already * been loaded by this class loader.
*/ privatefinal Vector<String> history = new Vector<String>();
privatebyte[] readResource(String className, String suffix) throws IOException { // Note to the unwary -- "/" works on Windows, leave it alone.
String fileName = className.replace('.', '/') + "." + suffix;
InputStream origStream = getResourceAsStream(fileName); if (origStream == null) { thrownew IOException("Resource not found : " + fileName);
}
BufferedInputStream stream = new java.io.BufferedInputStream(origStream); byte[] data = newbyte[stream.available()]; int how_many = stream.read(data); // Really ought to deal with the corner cases of stream.available() return data;
}
/** * Loads the named class from the system class loader unless * the name appears in either replaced or nonSystem. * nonSystem classes are loaded into this classloader, * and replaced classes get their content from the specified array * of bytes (and are also loaded into this classloader).
*/ protectedClass<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { Class<?> clazz;
if (history.contains(name)) { Class<?> c = this.findLoadedClass(name); return c;
} if (useSystemLoader(name)) {
clazz = findSystemClass(name); if (verbose) System.err.println("Loading system class " + name);
} else {
history.add(name); try { if (verbose) {
System.err.println("Loading classloader class " + name);
} byte[] classData = getClass(name); boolean expanded = false; if (!noReplace && replaced.containsKey(name)) { if (verbose) {
System.err.println("Replacing class " + name);
}
ClassReader cr = new ClassReader(classData);
ClassWriter cw = new ClassWriter(0);
VisitorMaker vm = replaced.get(name);
cr.accept(vm.make(cw), 0);
classData = cw.toByteArray();
}
clazz = defineClass(name, classData, 0, classData.length);
} catch (java.io.EOFException ioe) { thrownew ClassNotFoundException( "IO Exception in reading class : " + name + " ", ioe);
} catch (ClassFormatError ioe) { thrownew ClassNotFoundException( "ClassFormatError in reading class file: ", ioe);
} catch (IOException ioe) { thrownew ClassNotFoundException( "IO Exception in reading class file: ", ioe);
}
} if (clazz == null) { thrownew ClassNotFoundException(name);
} if (resolve) {
resolveClass(clazz);
} return clazz;
}
}
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.