List of usage examples for org.apache.commons.jci.readers ResourceReader ResourceReader
ResourceReader
From source file:cc.vidr.dejava.JavaSourceCompiler.java
public void compile() { result = compiler.compile(new String[] { fileName }, new ResourceReader() { public byte[] getBytes(String resourceName) { if (resourceName == fileName) return source.getBytes(); else/*from www . j av a 2s . c o m*/ return null; } public boolean isAvailable(String resourceName) { return resourceName == fileName; } }, new ResourceStore() { public byte[] read(String resourceName) { return classes.get(resourceName); } public void remove(String resourceName) { classes.remove(resourceName); } public void write(String resourceName, byte[] data) { classes.put(resourceName, data); } }); }
From source file:nl.tue.gale.common.code.JavaCodeUtil.java
private static byte[] compile(final String code) { final List<byte[]> result = new LinkedList<byte[]>(); CompilationResult cr = compiler.compile(new String[] { "Main.java" }, new ResourceReader() { public byte[] getBytes(String arg0) { try { if ("Main.java".equals(arg0)) return code.getBytes("UTF-8"); else return null; } catch (UnsupportedEncodingException e) { return null; }// www . jav a 2 s. c o m } public boolean isAvailable(String arg0) { return true; } }, new ResourceStore() { public byte[] read(String arg0) { return null; } public void remove(String arg0) { } public void write(String arg0, byte[] arg1) { result.add(arg1); } }); if (cr.getErrors().length > 0) throw new IllegalArgumentException("unable to compile code: " + cr.getErrors()[0].getMessage()); return result.get(0); }