@@ -66,10 +66,12 @@ public class ExecWebSocketListener extends WebSocketListener implements ExecWatc
66
66
private final InputStream in ;
67
67
private final OutputStream out ;
68
68
private final OutputStream err ;
69
+ private final OutputStream errChannel ;
69
70
70
71
private final PipedOutputStream input ;
71
72
private final PipedInputStream output ;
72
73
private final PipedInputStream error ;
74
+ private final PipedInputStream errorChannel ;
73
75
74
76
private final AtomicReference <WebSocket > webSocketRef = new AtomicReference <>();
75
77
private final ExecutorService executorService = Executors .newSingleThreadExecutor ();
@@ -92,16 +94,23 @@ public ExecWebSocketListener(InputStream in, OutputStream out, OutputStream err,
92
94
this (new Config (), in , out , err , inputPipe , outputPipe , errorPipe , listener );
93
95
}
94
96
97
+ @ Deprecated
95
98
public ExecWebSocketListener (Config config , InputStream in , OutputStream out , OutputStream err , PipedOutputStream inputPipe , PipedInputStream outputPipe , PipedInputStream errorPipe , ExecListener listener ) {
99
+ this (config , in , out , err , null , inputPipe , outputPipe , errorPipe , null , listener );
100
+ }
101
+
102
+ public ExecWebSocketListener (Config config , InputStream in , OutputStream out , OutputStream err , OutputStream errChannel , PipedOutputStream inputPipe , PipedInputStream outputPipe , PipedInputStream errorPipe , PipedInputStream errorChannelPipe , ExecListener listener ) {
96
103
this .config = config ;
97
104
this .listener = listener ;
98
105
this .in = inputStreamOrPipe (in , inputPipe , toClose );
99
106
this .out = outputStreamOrPipe (out , outputPipe , toClose );
100
107
this .err = outputStreamOrPipe (err , errorPipe , toClose );
108
+ this .errChannel = outputStreamOrPipe (errChannel , errorChannelPipe , toClose );
101
109
102
110
this .input = inputPipe ;
103
111
this .output = outputPipe ;
104
112
this .error = errorPipe ;
113
+ this .errorChannel = errorChannelPipe ;
105
114
this .pumper = new NonBlockingInputStreamPumper (this .in , new Callback <byte []>() {
106
115
@ Override
107
116
public void call (byte [] data ) {
@@ -182,6 +191,9 @@ public void onOpen(WebSocket webSocket, Response response) {
182
191
if (err instanceof PipedOutputStream && error != null ) {
183
192
error .connect ((PipedOutputStream ) err );
184
193
}
194
+ if (errChannel instanceof PipedOutputStream && errorChannel != null ) {
195
+ errorChannel .connect ((PipedOutputStream ) errChannel );
196
+ }
185
197
186
198
webSocketRef .set (webSocket );
187
199
executorService .submit (pumper );
@@ -242,8 +254,8 @@ public void onMessage(WebSocket webSocket, ByteString bytes) {
242
254
}
243
255
break ;
244
256
case 3 :
245
- if (err != null ) {
246
- err .write (byteString .toByteArray ());
257
+ if (errChannel != null ) {
258
+ errChannel .write (byteString .toByteArray ());
247
259
}
248
260
break ;
249
261
default :
@@ -290,6 +302,10 @@ public InputStream getError() {
290
302
return error ;
291
303
}
292
304
305
+ public InputStream getErrorChannel () {
306
+ return errorChannel ;
307
+ }
308
+
293
309
private void send (byte [] bytes ) throws IOException {
294
310
if (bytes .length > 0 ) {
295
311
WebSocket ws = webSocketRef .get ();
0 commit comments