KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > omg > lifl > eclipse > plugin > utils > StreamCatcher


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2003 USTL - LIFL - GOAL
5 Contact: openccm-team@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Jerome Offroy.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26 /*
27  * Created on 27 juin 2003
28  *
29  */

30 package org.omg.lifl.eclipse.plugin.utils;
31
32 import java.io.BufferedReader JavaDoc;
33 import java.io.IOException JavaDoc;
34 import java.io.InputStream JavaDoc;
35 import java.io.InputStreamReader JavaDoc;
36 import java.io.PrintStream JavaDoc;
37 import java.io.PrintWriter JavaDoc;
38
39 public class StreamCatcher extends Thread JavaDoc {
40     public boolean err_done;
41     public InputStream JavaDoc is;
42     public PrintStream JavaDoc os;
43     public String JavaDoc type;
44
45     public StreamCatcher(InputStream JavaDoc is, String JavaDoc type) {
46         os = null;
47         err_done = false;
48         this.is = is;
49         this.type = type;
50     }
51
52     public StreamCatcher(InputStream JavaDoc is, PrintStream JavaDoc os, String JavaDoc type) {
53         this.os = null;
54         err_done = false;
55         this.is = is;
56         this.os = os;
57         this.type = type;
58     }
59
60     public void set_err_done(boolean done)
61     {
62         err_done = done;
63     }
64
65     public void run()
66     {
67         try
68         {
69             InputStreamReader JavaDoc isr = new InputStreamReader JavaDoc(is);
70             BufferedReader JavaDoc br = new BufferedReader JavaDoc(isr);
71             PrintWriter JavaDoc pw = null;
72             if(os != null)
73                 pw = new PrintWriter JavaDoc(os);
74             String JavaDoc line = null;
75             if(type.compareTo("ERROR") == 0)
76                 while((line = br.readLine()) != null)
77                 {
78                     if(pw != null)
79                         pw.println(line);
80                     System.out.println("[OPENCCM]" + type + ">" + line);
81                     OutputToConsole.addError(line + "\n");
82                 }
83             else
84             if(type.compareTo("OUTPUT") == 0)
85                 while((line = br.readLine()) != null)
86                 {
87                     if(pw != null){
88                         //System.out.println("[DEBUG] pw");
89
pw.println(line);
90                     }
91                     //else System.out.println("[DEBUG] pas de pw");
92
System.out.println("[OPENCCM]" + type + ">" + line);
93                     if(line.indexOf(": error:") > 0 || line.indexOf(" error, ") > 0)
94                         OutputToConsole.addError(line + "\n");
95                     else
96                         OutputToConsole.addOutString(line + "\n");
97                 }
98         }
99         catch(IOException JavaDoc ioe)
100         {
101             ioe.printStackTrace();
102         }
103     }
104
105     }
106
Popular Tags