01: package gnu.mapping;
02:
03: import java.io.*;
04:
05: /** A class that supports an optional log file that output is duplicated to.
06: * This is used to implement the Scheme transcript facility. */
07:
08: public class LogWriter extends FilterWriter {
09: private Writer log;
10:
11: public LogWriter(Writer out) {
12: super (out);
13: }
14:
15: public final Writer getLogFile() {
16: return log;
17: }
18:
19: public void setLogFile(Writer log) {
20: this .log = log;
21: }
22:
23: public void setLogFile(String name) throws java.io.IOException {
24: // try
25: {
26: log = new PrintWriter(new BufferedWriter(new FileWriter(
27: name)));
28: }
29: // catch (??)
30: {
31: }
32: }
33:
34: public void closeLogFile() throws java.io.IOException {
35: if (log != null)
36: log.close();
37: log = null;
38: }
39:
40: public void write(int c) throws java.io.IOException {
41: if (log != null)
42: log.write(c);
43: super .write(c);
44: }
45:
46: public void echo(char buf[], int off, int len)
47: throws java.io.IOException {
48: if (log != null)
49: log.write(buf, off, len);
50: }
51:
52: public void write(char buf[], int off, int len)
53: throws java.io.IOException {
54: if (log != null)
55: log.write(buf, off, len);
56: super .write(buf, off, len);
57: }
58:
59: public void write(String str, int off, int len)
60: throws java.io.IOException {
61: if (log != null)
62: log.write(str, off, len);
63: super .write(str, off, len);
64: }
65:
66: public void flush() throws java.io.IOException {
67: if (log != null)
68: log.flush();
69: super .flush();
70: }
71:
72: public void close() throws java.io.IOException {
73: if (log != null)
74: log.close();
75: super.close();
76: }
77: }
|