1 26 30 package org.omg.lifl.eclipse.plugin.utils; 31 32 import java.io.BufferedReader ; 33 import java.io.IOException ; 34 import java.io.InputStream ; 35 import java.io.InputStreamReader ; 36 import java.io.PrintStream ; 37 import java.io.PrintWriter ; 38 39 public class StreamCatcher extends Thread { 40 public boolean err_done; 41 public InputStream is; 42 public PrintStream os; 43 public String type; 44 45 public StreamCatcher(InputStream is, String type) { 46 os = null; 47 err_done = false; 48 this.is = is; 49 this.type = type; 50 } 51 52 public StreamCatcher(InputStream is, PrintStream os, String 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 isr = new InputStreamReader (is); 70 BufferedReader br = new BufferedReader (isr); 71 PrintWriter pw = null; 72 if(os != null) 73 pw = new PrintWriter (os); 74 String 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 pw.println(line); 90 } 91 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 ioe) 100 { 101 ioe.printStackTrace(); 102 } 103 } 104 105 } 106 | Popular Tags |