Java Utililty Methods Class Loader

List of utility methods to do Class Loader

Description

The list of methods to do Class Loader are organized into topic(s).

Method

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));
...
ClassLoaderresolveClientClassLoader(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 {
...
ClassLoaderresolveServerClassLoader(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());
InputStreamtoInputStream(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();
StringtoString(ClassLoader loader)
to String
if (loader instanceof URLClassLoader) {
    URLClassLoader ul = (URLClassLoader) loader;
    return "URLClassLoader" + Arrays.asList(ul.getURLs()).toString();
return String.valueOf(loader);