Prompts and requests input.
String prompt = getPrompt(request);
InputStream in = null;
try {
in = getInputStream();
System.err.println(prompt);
System.err.flush();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
StreamPumper p = new StreamPumper(in, baos);
Thread t = new Thread(p);
t.start();
try {
t.join();
} catch (InterruptedException e) {
try {
t.join();
} catch (InterruptedException e2) {
// Ignore
}
}
request.setInput(new String(baos.toByteArray()));
if (!(request.isInputValid())) {
throw new BuildException(
"Received invalid console input");
}
if (p.getException() != null) {
throw new BuildException(
"Failed to read input from console", p.getException());
}
} finally {
FileUtils.close(in);
}