1 3 package jodd.io; 4 5 import java.io.FilterOutputStream ; 6 import java.io.IOException ; 7 import java.io.OutputStream ; 8 9 12 public class DebugOutputStream extends FilterOutputStream { 13 14 16 protected boolean passThrough = true; 17 18 21 public DebugOutputStream() { 22 super(System.out); 23 } 24 25 public DebugOutputStream(OutputStream out) { 26 super(out); 27 } 28 29 public DebugOutputStream(boolean passThrough) { 30 super(System.out); 31 this.passThrough = passThrough; 32 } 33 34 public DebugOutputStream(OutputStream out, boolean passThrough) { 35 super(out); 36 this.passThrough = passThrough; 37 } 38 39 40 42 public void close() throws IOException { 43 super.close(); 44 } 45 46 public void flush() throws IOException { 47 super.flush(); 48 } 49 50 public void write(int b) throws IOException { 51 if (passThrough == true) { 52 super.write(b); 53 } 54 dumpByte(b); 55 System.out.println(); 56 } 57 58 public void write(byte b[]) throws IOException { 59 super.write(b); 60 } 61 62 public void write(byte b[], int off, int len) throws IOException { 63 if (passThrough == true) { 64 super.write(b, off, len); 65 } 66 int i = off; 67 int count = len; 68 while (count-- > 0) { 69 dumpByte(b[i++]); 70 } 71 System.out.println(); 72 } 73 74 75 78 protected void dumpByte(int b) { 79 if (passThrough == true) { 80 System.out.print('\t'); 81 } 82 if (b < 0) { 83 b += 128; 84 } 85 if (b < 0x10) { 86 System.out.print('0'); 87 } 88 89 System.out.print(' '); 90 System.out.print(Integer.toHexString(b).toUpperCase()); 91 } 92 } 93 | Popular Tags |