@Test public void testGobbleMultiLineBlockingStream() throws Exception { PipedOutputStream pipedOutputStream = new PipedOutputStream(); PipedInputStream stream = new PipedInputStream(pipedOutputStream); ByteArrayOutputStream out = new ByteArrayOutputStream(); StreamGobbler gobbler = new StreamGobbler(stream, out, null); gobbler.start(); try { pipedOutputStream.write("line1\n".getBytes()); assertEqualsEventually(out, "line1" + NL); pipedOutputStream.write("line2\n".getBytes()); assertEqualsEventually(out, "line1" + NL + "line2" + NL); pipedOutputStream.write("line".getBytes()); pipedOutputStream.write("3\n".getBytes()); assertEqualsEventually(out, "line1" + NL + "line2" + NL + "line3" + NL); pipedOutputStream.close(); gobbler.join(10*1000); assertFalse(gobbler.isAlive()); assertEquals(new String(out.toByteArray()), "line1" + NL + "line2" + NL + "line3" + NL); } finally { gobbler.close(); gobbler.interrupt(); } }
@Override public void close() { running.set(false); interrupt(); }
StreamGobbler extends Thread implements Closeable { @Override public void close() { running.set(false); interrupt(); } }
StreamGobbler extends Thread implements Closeable { @Override public void close() { running.set(false); interrupt(); } StreamGobbler(InputStream stream, OutputStream out, Logger log);  StreamGobbler(InputStream stream, PrintStream out, Logger log); }
StreamGobbler extends Thread implements Closeable { @Override public void close() { running.set(false); interrupt(); } StreamGobbler(InputStream stream, OutputStream out, Logger log);  StreamGobbler(InputStream stream, PrintStream out, Logger log); @Override void close(); @Deprecated void shutdown(); StreamGobbler setPrefix(String prefix); StreamGobbler setPrintPrefix(String prefix); StreamGobbler setLogPrefix(String prefix); @Override void run(); void onChar(int c); void onLine(String line); void onClose(); void blockUntilFinished(); boolean isFinished(); }
StreamGobbler extends Thread implements Closeable { @Override public void close() { running.set(false); interrupt(); } StreamGobbler(InputStream stream, OutputStream out, Logger log);  StreamGobbler(InputStream stream, PrintStream out, Logger log); @Override void close(); @Deprecated void shutdown(); StreamGobbler setPrefix(String prefix); StreamGobbler setPrintPrefix(String prefix); StreamGobbler setLogPrefix(String prefix); @Override void run(); void onChar(int c); void onLine(String line); void onClose(); void blockUntilFinished(); boolean isFinished();  }