### Question:
StreamRedirectTask implements Runnable { @Override public void run() { boolean outputFailed = false; try { InputStream in = input; OutputStream out = output; byte[] buf = new byte[256]; while (true) { int read = in.read(buf); if (read == -1) { break; } if (outputFailed == false) { try { out.write(buf, 0, read); } catch (IOException e) { outputFailed = true; YSLOG.warn(e, "W99001"); } } } } catch (IOException e) { YSLOG.warn(e, "W99002"); } finally { if (closeInput) { close(input); } if (closeOutput) { close(output); } } } StreamRedirectTask(InputStream input, OutputStream output);  StreamRedirectTask(
            InputStream input, OutputStream output,
            boolean closeInput, boolean closeOutput); @Override void run();  }### Answer:
@Test(timeout = 10000) public void redirect() { StreamRedirectTask t = new StreamRedirectTask(in, out); t.run(); assertThat(out.toByteArray(), is(BYTES)); assertThat(in.read(), is(-1)); assertThat(in.closed, is(false)); assertThat(out.closed, is(false)); }
@Test(timeout = 10000) public void quietExitOnInputError() throws Exception { StreamRedirectTask t = new StreamRedirectTask(new ErroneousInputStream(65534), out); t.run(); }
@Test(timeout = 10000) public void quietExitOnOutputError() throws Exception { StreamRedirectTask t = new StreamRedirectTask(in, new ErroneousOutputStream(65534)); t.run(); assertThat("input stream must be consumed", in.read(), is(-1)); }
@Test(timeout = 10000) public void consumeInputOnOutputError() throws Exception { StreamRedirectTask t = new StreamRedirectTask(in, new ErroneousOutputStream(5)); t.run(); assertThat("input stream must be consumed", in.read(), is(-1)); }
@Test(timeout = 10000) public void closeInput() { StreamRedirectTask t = new StreamRedirectTask(in, out, true, false); t.run(); assertThat(out.toByteArray(), is(BYTES)); assertThat(in.closed, is(true)); assertThat(out.closed, is(false)); }
@Test(timeout = 10000) public void closeOutput() { StreamRedirectTask t = new StreamRedirectTask(in, out, false, true); t.run(); assertThat(out.toByteArray(), is(BYTES)); assertThat(in.closed, is(false)); assertThat(out.closed, is(true)); }