01: package gnu.jemacs.buffer;
02:
03: import java.io.*;
04: import gnu.mapping.*;
05:
06: /** Insert input from an InputStream into a buffer.
07: * This is typically output from an inferior process. */
08:
09: class InputStreamHandler extends Thread {
10: ProcessMode mode;
11: InputStream in;
12: BufferWriter wr;
13: Reader in_r;
14: char[] buffer;
15:
16: public InputStreamHandler(InputStream in, ProcessMode mode) {
17: this .in = in;
18: this .in_r = new InputStreamReader(in);
19: this .wr = new BufferWriter(mode.processMark, true);
20: this .mode = mode;
21: }
22:
23: public void run() {
24: try {
25: buffer = new char[512];
26: for (;;) {
27: int avail = in_r.read(buffer);
28: if (avail <= 0)
29: break;
30: wr.buffer = buffer;
31: wr.count = avail;
32: mode.invoke(wr);
33: //wr.write(buffer, 0, avail);
34: //wr.flush();
35: }
36: in.close();
37: } catch (Exception ex) {
38: throw new WrappedException(ex);
39: }
40: }
41: }
|