view src/kryshen/tema/io/CopyWriter.java @ 2:6c41a0b43e58

Tema 0.3 (imported from CVS).
author Mikhail Kryshen <mikhail@kryshen.net>
date Tue, 19 Feb 2008 20:32:17 +0300
parents
children e9d13c7ffeb1
line source
1 /*
2 * Copyright 2006-2008 Mikhail Kryshen
3 *
4 * This file is part of Tema.
5 *
6 * Tema is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation, either version 3 of the
9 * License, or (at your option) any later version.
10 *
11 * Tema is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the
17 * GNU Lesser General Public License along with Tema.
18 * If not, see <http://www.gnu.org/licenses/>.
19 *
20 * $Id: CopyWriter.java,v 1.7 2008/02/16 17:56:34 mikhail Exp $
21 */
23 package kryshen.tema.io;
25 import java.io.IOException;
26 import java.io.Writer;
28 /**
29 * Copies it's output to several writers.
30 *
31 * @author Mikhail Kryshen
32 */
33 public class CopyWriter extends Writer {
34 private final Writer[] writers;
36 public CopyWriter(Writer... writers) {
37 this.writers = writers;
38 }
40 public void write(char[] cbuf, int off, int len) throws IOException {
41 for (Writer w : writers) {
42 w.write(cbuf, off, len);
43 }
44 }
46 public void write(int c) throws IOException {
47 for (Writer w : writers) {
48 w.write(c);
49 }
50 }
52 public void write(String str, int off, int len) throws IOException {
53 for (Writer w : writers) {
54 w.write(str, off, len);
55 }
56 }
58 public void flush() throws IOException {
59 for (Writer w : writers) {
60 w.flush();
61 }
62 }
64 public void close() throws IOException {
65 for (Writer w : writers) {
66 w.close();
67 }
68 }
69 }