FileDocCategorySizeDatePackage
GreedyInputHandler.javaAPI DocApache Ant 1.702737Wed Dec 13 06:16:22 GMT 2006org.apache.tools.ant.input

GreedyInputHandler

public class GreedyInputHandler extends DefaultInputHandler
Prompts on System.err, reads input from System.in until EOF
since
Ant 1.7

Fields Summary
private static final int
BUFFER_SIZE
Constructors Summary
public GreedyInputHandler()
Empty no-arg constructor


            
      
    
Methods Summary
public voidhandleInput(InputRequest request)
Prompts and requests input.

param
request the request to handle
throws
BuildException if not possible to read from console, or if input is invalid.

        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);
        }