01: package antlr.build;
02:
03: import java.util.*;
04: import java.io.*;
05:
06: /** Adapted from JavaWorld article by Michael Daconta */
07: class StreamScarfer extends Thread {
08: InputStream is;
09: String type;
10: Tool tool;
11:
12: StreamScarfer(InputStream is, String type, Tool tool) {
13: this .is = is;
14: this .type = type;
15: this .tool = tool;
16: }
17:
18: public void run() {
19: try {
20: InputStreamReader isr = new InputStreamReader(is);
21: BufferedReader br = new BufferedReader(isr);
22: String line = null;
23: while ((line = br.readLine()) != null) {
24: if (type == null || type.equals("stdout")) {
25: tool.stdout(line);
26: } else {
27: tool.stderr(line);
28: }
29: }
30: } catch (IOException ioe) {
31: ioe.printStackTrace();
32: }
33: }
34: }
|