/** * @deprecate Use close() instead. */ @Deprecated public void shutdown() { close(); }
@Test public void testGobbleStream() throws Exception { byte[] bytes = new byte[] {'a','b','c'}; InputStream stream = new ByteArrayInputStream(bytes); ByteArrayOutputStream out = new ByteArrayOutputStream(); StreamGobbler gobbler = new StreamGobbler(stream, out, null); gobbler.start(); try { gobbler.join(10*1000); assertFalse(gobbler.isAlive()); assertEquals(new String(out.toByteArray()), "abc" + NL); } finally { gobbler.close(); gobbler.interrupt(); } }
@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()); pipedOutputStream.flush(); assertEqualsEventually(out, "line1" + NL); pipedOutputStream.write("line2\n".getBytes()); pipedOutputStream.flush(); assertEqualsEventually(out, "line1" + NL + "line2" + NL); pipedOutputStream.write("line".getBytes()); pipedOutputStream.write("3\n".getBytes()); pipedOutputStream.flush(); 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(); } }