InterpreterOutput extends OutputStream { public void flush() throws IOException { synchronized (outList) { buffer.flush(); byte[] bytes = buffer.toByteArray(); bytes = detectTypeFromLine(bytes); if (bytes != null) { outList.add(bytes); if (type == InterpreterResult.Type.TEXT) { flushListener.onAppend(this, bytes); } } buffer.reset(); } } InterpreterOutput(InterpreterOutputListener flushListener);  InterpreterOutput(InterpreterOutputListener flushListener,
                           InterpreterOutputChangeListener listener); InterpreterResult.Type getType(); void setType(InterpreterResult.Type type); void clear(); @Override void write(int b); @Override void write(byte [] b); @Override void write(byte [] b, int off, int len); void write(File file); void write(String string); void write(URL url); void writeResource(String resourceName); byte[] toByteArray(); void flush(); @Override void close();  }
@Test public void testFlush() throws IOException { out.write("hello\nworld"); assertEquals("hello\n", new String(out.toByteArray())); assertEquals(1, numAppendEvent); assertEquals(1, numUpdateEvent); out.flush(); assertEquals("hello\nworld", new String(out.toByteArray())); assertEquals(2, numAppendEvent); assertEquals(1, numUpdateEvent); out.clear(); out.write("%html div"); assertEquals("", new String(out.toByteArray())); assertEquals(InterpreterResult.Type.TEXT, out.getType()); out.flush(); out.write("%html div"); assertEquals("div", new String(out.toByteArray())); assertEquals(InterpreterResult.Type.HTML, out.getType()); }