All pastes #832834 Raw Edit

Something

public text v1 · immutable
#832834 ·published 2007-12-26 17:59 UTC
rendered paste body
    public static String prompt(String promptMessage, SVNCommandEnvironment env, boolean hide) throws SVNException {
        System.out.print(promptMessage);
        System.out.flush();
        StringBuffer input = null;
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try {
            while (true) {
                env.checkCancelled();
                if (!reader.ready()) {
                    SVNDebugLog.getDefaultLog().info("not ready..");
                    try {
                        Thread.sleep(1);
                    } catch (InterruptedException e) {
                        //
                    }
                    continue;
                }
                int r = reader.read();
                if (r == -1) {
                    SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.IO_ERROR,
                            "Can't read stdin: End of file found");
                    SVNErrorManager.error(err);
                }
                char ch = (char) (r & 0xFF);
                if (ch == '\n' || ch == '\r') {
                    if (input == null) {
                        input = new StringBuffer();
                    }
                    break;
                }
                if (input == null) {
                    input = new StringBuffer();
                }
                input.append(ch);
            }
        } catch (IOException ioe) {
            SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.IO_ERROR, "Can''t read stdin: {0}",
                    ioe.getLocalizedMessage());
            SVNErrorManager.error(err);
        }
        if (input == null) {
            SVNErrorMessage err  = SVNErrorMessage.create(SVNErrorCode.IO_ERROR, 
                    "Can't read stdin: End of file found");
            SVNErrorManager.error(err);
        }
        return input.toString();
    }