All Downloads are FREE. Search and download functionalities are using the official Maven repository.

rpc.turbo.util.SingleClassLoader Maven / Gradle / Ivy

The newest version!
package rpc.turbo.util;

/**
 * 单个类的类加载器
 * 
 * @author hank
 *
 */
public class SingleClassLoader extends ClassLoader {

	private final Class clazz;

	public SingleClassLoader(ClassLoader parent, byte[] bytes) {
		super(parent);
		this.clazz = defineClass(null, bytes, 0, bytes.length, null);
	}

	public Class getClazz() {
		return clazz;
	}

	@Override
	public Class loadClass(String name) throws ClassNotFoundException {
		if (clazz != null && clazz.getName().equals(name)) {
			return clazz;
		}

		return getParent().loadClass(name);
	}

	public static  Class loadClass(byte[] bytes) {
		ClassLoader parent = SingleClassLoader.class.getClassLoader();
		return loadClass(parent, bytes);
	}

	@SuppressWarnings("unchecked")
	public static  Class loadClass(ClassLoader parent, byte[] bytes) {
		return (Class) new SingleClassLoader(parent, bytes).getClazz();
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy