1 package gnu.mapping; 2 import java.io.*; 3 4 6 7 public class LogWriter extends FilterWriter 8 { 9 private Writer log; 10 11 public LogWriter (Writer out) 12 { 13 super (out); 14 } 15 16 public final Writer getLogFile () { return log; } 17 18 public void setLogFile (Writer log) 19 { 20 this.log = log; 21 } 22 23 public void setLogFile (String name) throws java.io.IOException 24 { 25 { 27 log = new PrintWriter(new BufferedWriter(new FileWriter(name))); 28 } 29 { 31 } 32 } 33 34 public void closeLogFile () throws java.io.IOException 35 { 36 if (log != null) 37 log.close(); 38 log = null; 39 } 40 41 public void write (int c) throws java.io.IOException 42 { 43 if (log != null) 44 log.write(c); 45 super.write(c); 46 } 47 48 public void echo (char buf[], int off, int len) throws java.io.IOException 49 { 50 if (log != null) 51 log.write(buf, off, len); 52 } 53 54 public void write (char buf[], int off, int len) throws java.io.IOException 55 { 56 if (log != null) 57 log.write(buf, off, len); 58 super.write(buf, off, len); 59 } 60 61 public void write (String str, int off, int len) throws java.io.IOException 62 { 63 if (log != null) 64 log.write(str, off, len); 65 super.write(str, off, len); 66 } 67 68 public void flush () throws java.io.IOException 69 { 70 if (log != null) 71 log.flush(); 72 super.flush(); 73 } 74 75 public void close () throws java.io.IOException 76 { 77 if (log != null) 78 log.close(); 79 super.close(); 80 } 81 } 82 | Popular Tags |