@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)); }
@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 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 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); }
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(); }
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();  }