// This will behave differently on desktop and Android. On the // desktop, it shows the program's output as it runs. On Android, // it does not. static S getProgramOutput(S progID) { if (isAndroid()) { PrintStream oldOut = System.out; PrintStream oldErr = System.err; new ByteArrayOutputStream baos; PrintStream ps = new PrintStream(baos, true); try { System.setOut(ps); System.setErr(ps); callMain(hotwire(progID)); ps.flush(); ret fromUtf8(baos.toByteArray()); // XXX - is this right? } finally { System.setOut(oldOut); System.setErr(oldErr); } } else { Class j = getJavaX(); Appendable oldSystemOut = (Appendable) get(j, "customSystemOut"); final new StringBuffer buf; set(j, "customSystemOut", new Appendable() { // only using this one public Appendable append(CharSequence cs) { buf.append(cs.toString()); return this; } public Appendable append(char c) { return this; } public Appendable append(CharSequence s, int start, int end) { return this; } }); try { callMain(hotwire(progID)); ret buf.toString(); } finally { set(j, "customSystemOut", oldSystemOut); } } }