Lines 55-60
Link Here
|
55 |
import java.io.UnsupportedEncodingException; |
55 |
import java.io.UnsupportedEncodingException; |
56 |
import java.io.Writer; |
56 |
import java.io.Writer; |
57 |
import java.lang.reflect.InvocationTargetException; |
57 |
import java.lang.reflect.InvocationTargetException; |
|
|
58 |
import java.util.concurrent.ExecutorService; |
59 |
import java.util.concurrent.Executors; |
58 |
|
60 |
|
59 |
import java.util.logging.Level; |
61 |
import java.util.logging.Level; |
60 |
import java.util.logging.Logger; |
62 |
import java.util.logging.Logger; |
Lines 99-146
Link Here
|
99 |
*/ |
101 |
*/ |
100 |
private static final class InputMonitor implements TermInputListener { |
102 |
private static final class InputMonitor implements TermInputListener { |
101 |
private final OutputStreamWriter outputStreamWriter; |
103 |
private final OutputStreamWriter outputStreamWriter; |
102 |
|
104 |
private final ExecutorService singlePool = Executors.newSingleThreadExecutor(); |
103 |
public InputMonitor(OutputStreamWriter outputStreamWriter) { |
105 |
public InputMonitor(OutputStreamWriter outputStreamWriter) { |
104 |
this.outputStreamWriter = outputStreamWriter; |
106 |
this.outputStreamWriter = outputStreamWriter; |
105 |
} |
107 |
} |
|
|
108 |
|
109 |
@Override |
110 |
public void sendChars(final char c[], final int offset, final int count) { |
111 |
singlePool.submit(new Runnable() { |
112 |
@Override |
113 |
public void run() { |
114 |
try { |
115 |
outputStreamWriter.write(c, offset, count); |
116 |
outputStreamWriter.flush(); |
117 |
} catch (IOException x) { |
118 |
// no-op |
119 |
} catch (Exception x) { |
120 |
Logger.getLogger(StreamTerm.class.getName()).log(Level.SEVERE, null, x); |
121 |
} |
122 |
} |
123 |
}); |
124 |
} |
106 |
|
125 |
|
107 |
@Override |
126 |
@Override |
108 |
public void sendChars(char c[], int offset, int count) { |
127 |
public void sendChar(final char c) { |
109 |
try { |
128 |
singlePool.submit(new Runnable() { |
110 |
outputStreamWriter.write(c, offset, count); |
129 |
@Override |
111 |
outputStreamWriter.flush(); |
130 |
public void run() { |
112 |
} catch (IOException x) { |
131 |
try { |
113 |
// no-op |
132 |
outputStreamWriter.write(c); |
114 |
} catch (Exception x) { |
133 |
// writer is buffered, need to use flush! |
115 |
Logger.getLogger(StreamTerm.class.getName()).log(Level.SEVERE, null, x); |
134 |
// perhaps SHOULD use an unbuffered writer? |
116 |
} |
135 |
// Also fix send_chars() |
117 |
} |
136 |
outputStreamWriter.flush(); |
118 |
|
137 |
} catch (IOException x) { |
119 |
@Override |
138 |
// no-op |
120 |
public void sendChar(char c) { |
139 |
} catch (Exception x) { |
121 |
try { |
140 |
Logger.getLogger(StreamTerm.class.getName()).log(Level.SEVERE, null, x); |
122 |
outputStreamWriter.write(c); |
141 |
} |
123 |
// writer is buffered, need to use flush! |
142 |
} |
124 |
// perhaps SHOULD use an unbuffered writer? |
143 |
}); |
125 |
// Also fix send_chars() |
144 |
} |
126 |
outputStreamWriter.flush(); |
|
|
127 |
} catch (IOException x) { |
128 |
// no-op |
129 |
} catch (Exception x) { |
130 |
Logger.getLogger(StreamTerm.class.getName()).log(Level.SEVERE, null, x); |
131 |
} |
132 |
} |
133 |
} |
145 |
} |
134 |
|
146 |
|
135 |
public StreamTerm() { |
147 |
public StreamTerm() { |
136 |
} |
148 |
} |
137 |
|
149 |
|
|
|
150 |
private static final int BUFSZ = 1024; |
138 |
/* |
151 |
/* |
139 |
* Monitor output from process and forward to terminal |
152 |
* Monitor output from process and forward to terminal |
140 |
*/ |
153 |
*/ |
141 |
private static final class OutputMonitor extends Thread { |
154 |
private static final class OutputMonitor extends Thread { |
142 |
|
155 |
|
143 |
private static final int BUFSZ = 1024; |
|
|
144 |
private final char[] buf = new char[BUFSZ]; |
156 |
private final char[] buf = new char[BUFSZ]; |
145 |
private final Term term; |
157 |
private final Term term; |
146 |
private final InputStreamReader reader; |
158 |
private final InputStreamReader reader; |
Lines 261-267
Link Here
|
261 |
} |
273 |
} |
262 |
} |
274 |
} |
263 |
} |
275 |
} |
264 |
|
|
|
265 |
/** |
276 |
/** |
266 |
* Connect an I/O stream pair or triple to this Term. |
277 |
* Connect an I/O stream pair or triple to this Term. |
267 |
* Call disconnect() before attempting to connect() again. |
278 |
* Call disconnect() before attempting to connect() again. |