1 22 package org.jboss.test.aop.jdk15.annotated.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 warnings.add(msg); 59 } 60 } 61 62 public static SystemOutDecorator initialise() 63 { 64 SystemOutDecorator sys = new SystemOutDecorator(System.out); 65 System.setOut(sys); 66 return sys; 67 } 68 69 public void kill() 70 { 71 System.setOut(sysout); 72 } 73 74 String getRidOfAllWhiteSpace(String msg) 75 { 76 StringBuffer sb = new StringBuffer (); 77 78 for (int i = 0 ; i < msg.length() ; i++) 79 { 80 char ch = msg.charAt(i); 81 if (ch != '\n' && ch != '\t' && ch != ' ' && ch != '\r') 82 { 83 sb.append(ch); 84 } 85 } 86 87 return sb.toString(); 88 } 89 } 90 | Popular Tags |