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