1 package com.quadcap.io; 2 3 40 41 import java.io.IOException ; 42 import java.io.Reader ; 43 import java.io.Writer ; 44 45 import com.quadcap.util.Debug; 46 import com.quadcap.util.Util; 47 48 54 55 public class LogWriter extends Writer { 56 Writer out; 57 Writer log; 58 String prefix; 59 boolean bol = true; 60 61 69 public LogWriter(Writer out, Writer log, String prefix) { 70 this.out = out; 71 this.log = log; 72 this.prefix = prefix; 73 } 74 75 80 synchronized public void write(int c) throws IOException { 81 out.write((char)c); 82 if (bol) log.write(prefix); 83 log.write((char)c); 84 bol = (c == '\n'); 85 } 86 87 90 public void write(char[] cbuf, int off, int len) throws IOException { 91 for (int i = 0; i < len; i++) { 92 write(cbuf[off + i]); 93 } 94 } 95 96 99 public void flush() throws IOException { 100 out.flush(); 101 log.flush(); 102 } 103 104 109 public void close() throws IOException { 110 out.close(); 111 } 112 } 113 | Popular Tags |