I need to write the same text to multiple files (or streams). Sometimes I need to use Writer, sometimes a PrintWriter, sometimes a OutputStream...
One way to do this in Java wold be to extend a PrintWriter to have an array of PrintWriters and overridde each method as follows:
class MutiplePrintWriter extends PrintWriter {
private PrintWriter[] outs;
public MutiplePrintWriter(PrintWriter[] outs) { this.out = out; }
public void print(boolean b) { for (PrintWriter out : outs) print(b); }
public void print(char c) { for (PrintWriter out : outs) print(c); }
public void print(char[] s) { for (PrintWriter out : outs) print(s); }
...
}
(and the same for Writer, OutputStream...)
Is there a better alternative in Scala?
Is this already implemented in a library in Scala?