19
19
import java .io .InputStream ;
20
20
import java .io .OutputStream ;
21
21
import java .util .concurrent .TimeUnit ;
22
-
23
22
import org .apache .commons .lang3 .StringUtils ;
24
23
25
24
public class Exec {
@@ -185,42 +184,42 @@ private static class ExecProcess extends Process {
185
184
186
185
public ExecProcess () throws IOException {
187
186
this .statusCode = -1 ;
188
- this .streamHandler = new WebSocketStreamHandler () {
189
- @ Override
190
- public void close () {
191
- if (statusCode == -1 ) {
192
- InputStream inputStream = getInputStream (3 );
193
- int exitCode = 0 ;
194
- try {
195
- int available = inputStream .available ();
196
- if (available > 0 ) {
197
- byte [] b = new byte [available ];
198
- inputStream .read (b );
199
- String result = new String (b , "UTF-8" );
200
- int idx = result .lastIndexOf (':' );
201
- if (idx > 0 ) {
202
- try {
203
- exitCode = Integer .parseInt (result .substring (idx + 1 ).trim ());
204
- } catch (NumberFormatException nfe ) {
205
- // no-op
187
+ this .streamHandler =
188
+ new WebSocketStreamHandler () {
189
+ @ Override
190
+ public void close () {
191
+ if (statusCode == -1 ) {
192
+ InputStream inputStream = getInputStream (3 );
193
+ int exitCode = 0 ;
194
+ try {
195
+ int available = inputStream .available ();
196
+ if (available > 0 ) {
197
+ byte [] b = new byte [available ];
198
+ inputStream .read (b );
199
+ String result = new String (b , "UTF-8" );
200
+ int idx = result .lastIndexOf (':' );
201
+ if (idx > 0 ) {
202
+ try {
203
+ exitCode = Integer .parseInt (result .substring (idx + 1 ).trim ());
204
+ } catch (NumberFormatException nfe ) {
205
+ // no-op
206
+ }
207
+ }
206
208
}
209
+ } catch (IOException e ) {
210
+ }
211
+
212
+ // notify of process completion
213
+ synchronized (ExecProcess .this ) {
214
+ statusCode = exitCode ;
215
+ ExecProcess .this .notifyAll ();
207
216
}
208
217
}
209
- } catch (IOException e ) {
210
- }
211
-
212
- // notify of process completion
213
- synchronized (ExecProcess .this ) {
214
- statusCode = exitCode ;
215
- ExecProcess .this .notifyAll ();
218
+ super .close ();
216
219
}
217
- }
218
- super .close ();
219
- }
220
-
221
- };
220
+ };
222
221
}
223
-
222
+
224
223
private WebSocketStreamHandler getHandler () {
225
224
return streamHandler ;
226
225
}
@@ -247,20 +246,18 @@ public int waitFor() throws InterruptedException {
247
246
}
248
247
return statusCode ;
249
248
}
250
-
249
+
251
250
@ Override
252
- public boolean waitFor (long timeout , TimeUnit unit )
253
- throws InterruptedException {
251
+ public boolean waitFor (long timeout , TimeUnit unit ) throws InterruptedException {
254
252
synchronized (this ) {
255
253
this .wait (TimeUnit .MILLISECONDS .convert (timeout , unit ));
256
254
}
257
255
return !isAlive ();
258
256
}
259
-
257
+
260
258
@ Override
261
259
public int exitValue () {
262
- if (statusCode == -1 )
263
- throw new IllegalThreadStateException ();
260
+ if (statusCode == -1 ) throw new IllegalThreadStateException ();
264
261
return statusCode ;
265
262
}
266
263
0 commit comments