@Override public void close() throws IOException { if (out == null) return; out.close(); out = null; cleanupTee(); } private void cleanupTee() throws IOException {
@Override public void write(byte[] b, int off, int len) throws IOException { if (out == null) throw new IOException("Output Stream closed"); out.write(b, off, len); writeTee(b, off, len); } private void writeTee(byte[] b, int off, int len) throws IOException {
public void write(OutputStream out) throws IOException { if (logger != null) { OutputStream tee = logger.getPrintStream(); long max = logger.getContentMax(); if (tee != null && max > 0) { handle.write(new OutputStreamTee(out, tee, max)); return; } } handle.write(out); } }
@Override public void writeTo(BufferedSink sink) throws IOException { OutputStream out = sink.outputStream(); if (logger != null) { OutputStream tee = logger.getPrintStream(); long max = logger.getContentMax(); if (tee != null && max > 0) { handle.write(new OutputStreamTee(out, tee, max)); return; } } handle.write(out); } }
OutputStream tee = new OutputStreamTee(mainOutputStream, out, Long.MAX_VALUE); tee.write(expectedString.getBytes()); byte[] mainBytes = mainOutputStream.toByteArray();
@Override public void close() throws IOException { if (out == null) return; out.close(); out = null; cleanupTee(); } private void cleanupTee() throws IOException {
@Override public void write(byte[] b) throws IOException { if (out == null) throw new IOException("Output Stream closed"); out.write(b); writeTee(b, 0, b.length); } @Override
private void writeTee(byte[] b, int off, int len) throws IOException { if (max == Long.MAX_VALUE) { tee.write(b, off, len); return; } else if (sent >= max) { return; } int teeLen = ((sent + len) <= max) ? len : (int) (max - sent); sent += teeLen; tee.write(b, off, teeLen); if (sent >= max) cleanupTee(); }
@Override public void write(byte[] b) throws IOException { if (out == null) throw new IOException("Output Stream closed"); out.write(b); writeTee(b, 0, b.length); } @Override
private void writeTee(byte[] b, int off, int len) throws IOException { if (max == Long.MAX_VALUE) { tee.write(b, off, len); return; } else if (sent >= max) { return; } int teeLen = ((sent + len) <= max) ? len : (int) (max - sent); sent += teeLen; tee.write(b, off, teeLen); if (sent >= max) cleanupTee(); }
@Override public void write(byte[] b, int off, int len) throws IOException { if (out == null) throw new IOException("Output Stream closed"); out.write(b, off, len); writeTee(b, off, len); } private void writeTee(byte[] b, int off, int len) throws IOException {
@Override public void write(int b) throws IOException { if (out == null) throw new IOException("Output Stream closed"); out.write(b); if (max == Long.MAX_VALUE) { tee.write(b); return; } else if (sent >= max) { return; } tee.write(b); sent++; if (sent == max) cleanupTee(); } @Override
@Override public void write(int b) throws IOException { if (out == null) throw new IOException("Output Stream closed"); out.write(b); if (max == Long.MAX_VALUE) { tee.write(b); return; } else if (sent >= max) { return; } tee.write(b); sent++; if (sent == max) cleanupTee(); } @Override