1 22 package org.jboss.test.aop.declare; 23 24 import java.io.OutputStream ; 25 import java.io.PrintStream ; 26 import java.util.ArrayList ; 27 28 35 public class SystemOutDecorator extends PrintStream 36 { 37 static PrintStream sysout = null; 38 ArrayList warnings = new ArrayList (); 39 public SystemOutDecorator(OutputStream out) 40 { 41 super(out); 42 sysout = System.out; 43 } 44 45 public ArrayList getWarnings() 46 { 47 return warnings; 48 } 49 50 public void println(String msg) 51 { 52 super.println(msg); 53 if (msg.startsWith("WARNING:")) 54 { 55 System.out.println(">>>>>"); 56 super.println(msg); 57 System.out.println("<<<<<"); 58 msg = getRidOfAllWhiteSpace(msg); 59 warnings.add(msg); 60 } 61 } 62 63 public static SystemOutDecorator initialise() 64 { 65 SystemOutDecorator sys = new SystemOutDecorator(System.out); 66 System.setOut(sys); 67 return sys; 68 } 69 70 public void kill() 71 { 72 System.setOut(sysout); 73 } 74 75 String getRidOfAllWhiteSpace(String msg) 76 { 77 StringBuffer sb = new StringBuffer (); 78 79 for (int i = 0 ; i < msg.length() ; i++) 80 { 81 char ch = msg.charAt(i); 82 if (ch != '\n' && ch != '\t' && ch != ' ' && ch != '\r') 83 { 84 sb.append(ch); 85 } 86 } 87 88 return sb.toString(); 89 } 90 } 91 | Popular Tags |