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 53 54 public class LogInputStream extends InputStream { 55 InputStream in; 56 OutputStream log; 57 byte[] prefix; 58 boolean bol = true; 59 60 68 public LogInputStream(InputStream is, OutputStream log, String prefix) { 69 this.in = is; 70 this.log = log; 71 this.prefix = prefix.getBytes(); 72 } 73 74 79 synchronized public int read() throws IOException { 80 int b = in.read(); 81 if (bol) log.write(prefix); 82 log.write(b); 83 bol = (b == '\n'); 84 return b; 85 } 86 87 92 public void close() throws IOException { 93 in.close(); 94 log.close(); 95 } 96 } 97 | Popular Tags |