1 19 20 21 package ca.mcgill.sable.soot.util; 22 23 import java.io.*; 24 25 26 import org.eclipse.swt.widgets.Display; 27 28 import ca.mcgill.sable.soot.*; 29 import ca.mcgill.sable.soot.launching.*; 30 31 32 public class StreamGobbler extends Thread { 33 34 public static final int OUTPUT_STREAM_TYPE = 0; 35 public static final int ERROR_STREAM_TYPE = 1; 36 37 private InputStream is; 38 private int type; 39 private Display display; 40 41 42 public StreamGobbler(Display display, InputStream is, int type) { 43 setIs(is); 44 setType(type); 45 setDisplay(display); 46 47 } 48 49 public void run() { 50 try { 51 InputStreamReader isr = new InputStreamReader(getIs()); 52 BufferedReader br = new BufferedReader(isr); 53 54 while (true) { 55 String temp = br.readLine(); 56 57 if (temp == null) break; 58 59 SootOutputEvent se = new SootOutputEvent(this, ISootOutputEventConstants.SOOT_NEW_TEXT_EVENT); 60 se.setTextToAppend(temp); 61 final SootOutputEvent toSend = se; 62 63 getDisplay().asyncExec(new Runnable (){ 64 public void run() { 65 SootPlugin.getDefault().fireSootOutputEvent(toSend); 66 67 }; 68 }); 69 se = new SootOutputEvent(this, ISootOutputEventConstants.SOOT_NEW_TEXT_EVENT); 70 se.setTextToAppend("\n"); 71 final SootOutputEvent newline = se; 72 getDisplay().asyncExec(new Runnable (){ 73 public void run() { 74 SootPlugin.getDefault().fireSootOutputEvent(newline); 75 }; 76 }); 77 78 } 79 } 80 catch(IOException e1) { 81 System.out.println(e1.getMessage()); 82 } 83 } 84 85 89 public InputStream getIs() { 90 return is; 91 } 92 93 97 public int getType() { 98 return type; 99 } 100 101 105 public void setIs(InputStream is) { 106 this.is = is; 107 } 108 109 113 public void setType(int type) { 114 this.type = type; 115 } 116 117 121 public Display getDisplay() { 122 return display; 123 } 124 125 129 public void setDisplay(Display display) { 130 this.display = display; 131 } 132 133 } 134 | Popular Tags |