ch.obermuhlner.scriptengine.java.MemoryClassLoader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-scriptengine Show documentation
Show all versions of java-scriptengine Show documentation
Java script engine for Java as a scripting language.
package ch.obermuhlner.scriptengine.java;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;
public class MemoryClassLoader extends ClassLoader {
private Map mapClassBytes;
MemoryClassLoader(Map mapClassBytes, ClassLoader parent) {
super(parent);
this.mapClassBytes = mapClassBytes;
}
@Override
public Class> loadClass(String name) throws ClassNotFoundException {
byte[] bytes = mapClassBytes.get(name);
if (bytes == null) {
return super.loadClass(name);
}
return defineClass(name, bytes, 0, bytes.length);
}
}