use of org.gradle.util.StdinSwapper in project gradle by gradle.
the class ForwardClientInput method execute.
public void execute(final DaemonCommandExecution execution) {
final PipedOutputStream inputSource = new PipedOutputStream();
final PipedInputStream replacementStdin;
try {
replacementStdin = new PipedInputStream(inputSource);
} catch (IOException e) {
throw UncheckedException.throwAsUncheckedException(e);
}
execution.getConnection().onStdin(new StdinHandler() {
public void onInput(ForwardInput input) {
LOGGER.debug("Writing forwarded input on daemon's stdin.");
try {
inputSource.write(input.getBytes());
} catch (IOException e) {
LOGGER.warn("Received exception trying to forward client input.", e);
}
}
public void onEndOfInput() {
LOGGER.info("Closing daemon's stdin at end of input.");
try {
inputSource.close();
} catch (IOException e) {
LOGGER.warn("Problem closing output stream connected to replacement stdin", e);
} finally {
LOGGER.info("The daemon will no longer process any standard input.");
}
}
});
try {
try {
new StdinSwapper().swap(replacementStdin, new Callable<Void>() {
public Void call() {
execution.proceed();
return null;
}
});
} finally {
execution.getConnection().onStdin(null);
IOUtils.closeQuietly(replacementStdin);
IOUtils.closeQuietly(inputSource);
}
} catch (Exception e) {
throw UncheckedException.throwAsUncheckedException(e);
}
}
Aggregations