KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > aop > annotated > declare > SystemOutDecorator


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7
8 package org.jboss.test.aop.annotated.declare;
9
10 import java.io.OutputStream JavaDoc;
11 import java.io.PrintStream JavaDoc;
12 import java.util.ArrayList JavaDoc;
13
14 /**
15  * Wraps calls to System.out.println(String), and stores all Strings beginning
16  * with "WARNING:"
17  *
18  * @author <a HREF="mailto:kabir.khan@jboss.org">Kabir Khan</a>
19  * @version $Revision: 1.1.8.2 $
20  */

21 public class SystemOutDecorator extends PrintStream JavaDoc
22 {
23    static PrintStream JavaDoc sysout = null;
24    ArrayList JavaDoc warnings = new ArrayList JavaDoc();
25    public SystemOutDecorator(OutputStream JavaDoc out)
26    {
27       super(out);
28       sysout = System.out;
29    }
30    
31    public ArrayList JavaDoc getWarnings()
32    {
33       return warnings;
34    }
35    
36    public void println(String JavaDoc 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 JavaDoc getRidOfAllWhiteSpace(String JavaDoc msg)
61    {
62       StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
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