Skip to content

Instantly share code, notes, and snippets.

@abcdabcd987
Created April 24, 2016 05:30
Show Gist options
  • Save abcdabcd987/dbc9c82ccba90707da3e6f7d47a6468f to your computer and use it in GitHub Desktop.
Save abcdabcd987/dbc9c82ccba90707da3e6f7d47a6468f to your computer and use it in GitHub Desktop.
Write to multiple OutputStream
package com.abcdabcd987.compiler2016.Utility;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.List;
/**
* Created by abcdabcd987 on 2016-04-18.
*/
public class TeeOutputStream extends OutputStream {
private OutputStream[] streams;
public TeeOutputStream(OutputStream... streams) {
super();
this.streams = streams;
}
@Override
public void write(int b) throws IOException {
for (OutputStream stream : streams) stream.write(b);
}
@Override
public void write(byte[] b) throws IOException {
for (OutputStream stream : streams) stream.write(b);
}
@Override
public void write(byte[] b, int off, int len) throws IOException {
for (OutputStream stream : streams) stream.write(b, off, len);
}
@Override
public void flush() throws IOException {
for (OutputStream stream : streams) stream.flush();
}
@Override
public void close() throws IOException {
super.close();
// do not close streams
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment