Created
April 24, 2016 05:30
-
-
Save abcdabcd987/dbc9c82ccba90707da3e6f7d47a6468f to your computer and use it in GitHub Desktop.
Write to multiple OutputStream
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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