1 package com.quadcap.io; 2 3 40 41 import java.io.*; 42 43 import com.quadcap.util.Debug; 44 import com.quadcap.util.Util; 45 46 51 52 public class LogOutputStream extends OutputStream { 53 OutputStream out; 54 OutputStream log; 55 byte[] prefix; 56 boolean bol = true; 57 58 66 public LogOutputStream(OutputStream os, OutputStream log, String prefix) { 67 this.out = os; 68 this.log = log; 69 this.prefix = prefix.getBytes(); 70 } 71 72 78 synchronized public void write(int b) throws IOException { 79 out.write(b); 80 if (bol) log.write(prefix); 81 log.write(b); 82 bol = (b == '\n'); 83 } 84 85 94 synchronized public void write(byte[] b, int off, int len) 95 throws IOException 96 { 97 for (int i = 0; i < len; i++) write(b[off+i]); 98 } 99 100 107 synchronized public void write(byte[] b) throws IOException { 108 write(b, 0, b.length); 109 } 110 111 116 public void close() throws IOException { 117 out.close(); 118 log.close(); 119 } 120 121 126 public void flush() throws IOException { 127 out.flush(); 128 } 129 } 130 | Popular Tags |