use of org.gradle.util.internal.DisconnectableInputStream in project gradle by gradle.
the class InputForwarder method start.
public InputForwarder start() {
lifecycleLock.lock();
try {
if (started) {
throw new IllegalStateException("input forwarder has already been started");
}
disconnectableInput = new DisconnectableInputStream(input, bufferSize);
outputBuffer = new LineBufferingOutputStream(handler, SystemProperties.getInstance().getLineSeparator(), bufferSize);
forwardingExecuter = executorFactory.create("Forward input");
forwardingExecuter.execute(new Runnable() {
@Override
public void run() {
byte[] buffer = new byte[bufferSize];
int readCount;
Throwable readFailure = null;
try {
while (true) {
try {
readCount = disconnectableInput.read(buffer, 0, bufferSize);
if (readCount < 0) {
break;
}
} catch (AsynchronousCloseException e) {
break;
} catch (IOException e) {
readFailure = e;
break;
}
outputBuffer.write(buffer, 0, readCount);
}
// will flush any unterminated lines out synchronously
outputBuffer.flush();
} catch (IOException e) {
// should not happen
throw UncheckedException.throwAsUncheckedException(e);
} finally {
handler.endOfStream(readFailure);
}
}
});
started = true;
} finally {
lifecycleLock.unlock();
}
return this;
}
use of org.gradle.util.internal.DisconnectableInputStream in project gradle by gradle.
the class ContinuousBuildActionExecutor method createCancellableOperationManager.
private CancellableOperationManager createCancellableOperationManager(BuildRequestMetaData requestContext, BuildCancellationToken cancellationToken) {
final CancellableOperationManager cancellableOperationManager;
if (requestContext.isInteractive()) {
if (!(System.in instanceof DisconnectableInputStream)) {
System.setIn(new DisconnectableInputStream(System.in));
}
DisconnectableInputStream inputStream = (DisconnectableInputStream) System.in;
cancellableOperationManager = new DefaultCancellableOperationManager(executorFactory.create("Cancel signal monitor"), inputStream, cancellationToken);
} else {
cancellableOperationManager = new PassThruCancellableOperationManager(cancellationToken);
}
return cancellableOperationManager;
}
use of org.gradle.util.internal.DisconnectableInputStream in project gradle by gradle.
the class ForwardStdinStreamsHandler method connectStreams.
@Override
public void connectStreams(Process process, String processName, Executor executor) {
this.executor = executor;
/*
There's a potential problem here in that DisconnectableInputStream reads from input in the background.
This won't automatically stop when the process is over. Therefore, if input is not closed then this thread
will run forever. It would be better to ensure that this thread stops when the process does.
*/
InputStream instr = new DisconnectableInputStream(input);
standardInputWriter = new ExecOutputHandleRunner("write standard input to " + processName, instr, process.getOutputStream(), completed);
}
Aggregations