List of utility methods to do Class Loader
byte[] | readBytecodeForClass(ClassLoader loader, String className, boolean mustExist) read Bytecode For Class String path = toClassPath(className); InputStream stream = null; try { stream = getStreamForPath(loader, path); if (stream == null) { if (mustExist) throw new RuntimeException(String .format("Unable to locate class file for '%s' in class loader %s.", className, loader)); ... |
ClassLoader | resolveClientClassLoader(Map env) Get the Connector Client default class loader. if (env == null) return Thread.currentThread().getContextClassLoader(); Object loader = env.get(DEFAULT_CLASS_LOADER); if (loader == null) return Thread.currentThread().getContextClassLoader(); if (loader instanceof ClassLoader) { return (ClassLoader) loader; } else { ... |
ClassLoader | resolveServerClassLoader(Map env, MBeanServer mbs) Get the Connector Server default class loader. if (env == null) return Thread.currentThread().getContextClassLoader(); Object loader = env.get(DEFAULT_CLASS_LOADER); Object name = env.get(DEFAULT_CLASS_LOADER_NAME); if (loader != null && name != null) { final String msg = "Only one of " + DEFAULT_CLASS_LOADER + " or " + DEFAULT_CLASS_LOADER_NAME + " should be specified."; throw new IllegalArgumentException(msg); ... |
Set | scanPackage(ClassLoader classLoader, Package pkg) scan Package return scanPackage(classLoader, pkg.getName());
|
InputStream | toInputStream(String name, ClassLoader cl) to Input Stream File file = new File(name); if (file.exists()) { return new FileInputStream(file); } else { URL url = cl.getResource(name); return url.openStream(); |
String | toString(ClassLoader loader) to String if (loader instanceof URLClassLoader) { URLClassLoader ul = (URLClassLoader) loader; return "URLClassLoader" + Arrays.asList(ul.getURLs()).toString(); return String.valueOf(loader); |