com.github.skjolber.stcsv.CsvReaderClassLoader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of databinder Show documentation
Show all versions of databinder Show documentation
High-performance CSV databinding library
package com.github.skjolber.stcsv;
import java.util.Objects;
public class CsvReaderClassLoader {
protected final ClassLoader contextClassLoader;
public CsvReaderClassLoader(ClassLoader contextClassLoader) {
this.contextClassLoader = contextClassLoader;
}
@SuppressWarnings("unchecked")
public Class extends T> load(byte[] classBytes, String className) throws Exception {
return (Class extends T>) new DynamicClassLoader(contextClassLoader, classBytes, className).loadClass(className);
}
protected static class DynamicClassLoader extends ClassLoader {
protected byte[] classBytes;
protected final String className;
protected DynamicClassLoader(ClassLoader contextClassLoader, byte[] classBytes, String className) {
super(contextClassLoader);
this.classBytes = classBytes;
this.className = className;
}
@Override
public Class> findClass(String className) throws ClassNotFoundException {
if (Objects.equals(this.className, className)) {
return defineClass(className, this.classBytes, 0, this.classBytes.length);
}
throw new ClassNotFoundException(className);
}
}
}