diff -r e078953818d2 -r 86f3ea771e24 launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Console.java --- a/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Console.java Thu Dec 20 11:03:34 2012 +0100 +++ b/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Console.java Thu Dec 20 21:54:33 2012 +0100 @@ -17,9 +17,12 @@ */ package org.apidesign.bck2brwsr.launcher; +import java.io.IOException; +import java.io.InputStream; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.URL; +import java.util.Enumeration; import org.apidesign.bck2brwsr.core.JavaScriptBody; /** @@ -89,6 +92,37 @@ return r == null ? "null" : r.toString().toString(); } + /** Helper method that inspects the classpath and loads given resource + * (usually a class file). Used while running tests in Rhino. + * + * @param name resource name to find + * @return the array of bytes in the given resource + * @throws IOException I/O in case something goes wrong + */ + public static byte[] read(String name) throws IOException { + URL u = null; + Enumeration en = Console.class.getClassLoader().getResources(name); + while (en.hasMoreElements()) { + u = en.nextElement(); + } + if (u == null) { + throw new IOException("Can't find " + name); + } + try (InputStream is = u.openStream()) { + byte[] arr; + arr = new byte[is.available()]; + int offset = 0; + while (offset < arr.length) { + int len = is.read(arr, offset, arr.length - offset); + if (len == -1) { + throw new IOException("Can't read " + name); + } + offset += len; + } + return arr; + } + } + private static Object invokeMethod(String clazz, String method) throws ClassNotFoundException, InvocationTargetException, SecurityException, IllegalAccessException, IllegalArgumentException {