TeeWriter extends Writer { @Override public synchronized void write(char[] cbuf, int off, int len) throws IOException { for (Writer writer : writers) { writer.write(cbuf, off, len); } } TeeWriter(Writer... writers);  TeeWriter(Iterable<? extends Writer> writers); @Override synchronized void write(char[] cbuf, int off, int len); @Override void flush(); @Override void close();  }
@Test public void testWrite() throws Exception { StringWriter one = new StringWriter(); StringWriter two = new StringWriter(); StringWriter three = new StringWriter(); try (TeeWriter tee = new TeeWriter(one, two, three)) { String text = "The quick brown fox"; tee.append(text); tee.flush(); assertEquals(text, one.getBuffer().toString()); assertEquals(text, two.getBuffer().toString()); assertEquals(text, one.getBuffer().toString()); } }