summaryrefslogtreecommitdiff
path: root/base
diff options
context:
space:
mode:
Diffstat (limited to 'base')
-rw-r--r--base/src/main/java/bjc/utils/ioutils/MirrorOutputStream.java63
1 files changed, 63 insertions, 0 deletions
diff --git a/base/src/main/java/bjc/utils/ioutils/MirrorOutputStream.java b/base/src/main/java/bjc/utils/ioutils/MirrorOutputStream.java
new file mode 100644
index 0000000..6906201
--- /dev/null
+++ b/base/src/main/java/bjc/utils/ioutils/MirrorOutputStream.java
@@ -0,0 +1,63 @@
+package bjc.utils.ioutils;
+
+import java.io.*;
+import java.util.*;
+
+/**
+ * An output stream that mirrors its contents to other streams.
+ *
+ * @author Ben Culkin
+ *
+ */
+public class MirrorOutputStream extends OutputStream {
+ private List<OutputStream> streams;
+
+ /**
+ * Create a new mirroring output stream.
+ *
+ * @param strams
+ * The output streams to mirror to.
+ */
+ public MirrorOutputStream(OutputStream... strams) {
+ streams = new ArrayList<>();
+
+ for (OutputStream stram : strams) {
+ streams.add(stram);
+ }
+ }
+
+ @Override
+ public void close() throws IOException {
+ for (OutputStream stream : streams) {
+ stream.close();
+ }
+ }
+
+ @Override
+ public void flush() throws IOException {
+ for (OutputStream stream : streams) {
+ stream.flush();
+ }
+ }
+
+ @Override
+ public void write(byte[] ba) throws IOException {
+ for (OutputStream stream : streams) {
+ stream.write(ba);
+ }
+ }
+
+ @Override
+ public void write(byte[] ba, int off, int len) throws IOException {
+ for (OutputStream stream : streams) {
+ stream.write(ba, off, len);
+ }
+ }
+
+ @Override
+ public void write(int b) throws IOException {
+ for (OutputStream stream : streams) {
+ stream.write(b);
+ }
+ }
+}