use of primal.jdk.UnsafeUtil in project suite by stupidsing.
the class JdkUtil method load.
private <T> Class<? extends T> load(Class<T> interfaceClazz, String canonicalName, Path path) {
Log_.info("Loading class " + canonicalName);
var bytes = ReadFile.from(path).readBytes();
return new UnsafeUtil().defineClass(interfaceClazz, canonicalName, bytes);
}
use of primal.jdk.UnsafeUtil in project suite by stupidsing.
the class JdkUtilTest method compile.
private <I> Class<? extends I> compile(Class<I> clazz, String className, String source) {
var filename = className.replace('.', '/') + ".java";
var baos_ = new ByteArrayOutputStream();
try (var baos = baos_) {
var sjfo = new SimpleJavaFileObject(URI.create(filename), Kind.SOURCE) {
public CharSequence getCharContent(boolean ignoreEncodingErrors) {
return source;
}
public OutputStream openOutputStream() {
return baos;
}
};
var sfm = ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null);
var jfm = new ForwardingJavaFileManager<>(sfm) {
public JavaFileObject getJavaFileForOutput(Location loc, String clazz, Kind kind, FileObject sibling) {
return sjfo;
}
};
ToolProvider.getSystemJavaCompiler().getTask(null, jfm, null, null, null, List.of(sjfo)).call();
} catch (IOException ex) {
fail(ex);
}
return new UnsafeUtil().defineClass(clazz, filename, baos_.toByteArray());
}
Aggregations