org.zalando.riptide.logbook.TeeOutputStream Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of riptide-logbook Show documentation
Show all versions of riptide-logbook Show documentation
Client side response routing
package org.zalando.riptide.logbook;
import lombok.AllArgsConstructor;
import java.io.IOException;
import java.io.OutputStream;
import static org.zalando.fauxpas.TryWith.tryWith;
@AllArgsConstructor
final class TeeOutputStream extends OutputStream {
private final OutputStream original;
private final OutputStream branch;
@Override
public void write(final byte[] b) throws IOException {
original.write(b);
branch.write(b);
}
@Override
public void write(final byte[] b, final int off, final int len) throws IOException {
original.write(b, off, len);
branch.write(b, off, len);
}
@Override
public void write(final int b) throws IOException {
original.write(b);
branch.write(b);
}
@Override
public void flush() throws IOException {
original.flush();
branch.flush();
}
@Override
public void close() {
tryWith(original, branch, (ignored, ignoredToo) -> {
// nothing to do
});
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy