protected Editline() { super(); // // 50 minutes // _timeout = new PromptTimeout(50 * 60 * 1000, Thread.currentThread()); _timeout.start(); }
/** * Displays a prompt on stadout and read a string from stdin. NULL is returned if the user presses * enter, rather than an empty String. EOFException is thrown if the user hits CTRL-D, */ public String readline(String prompt, boolean useEditline) throws EOFException, IOException, UnsupportedEncodingException { String line = ""; try { _timeout.arm(); // System.out.println ("_useEditline: " + _useEditline); // System.out.println ("useEditline: " + useEditline); if (_useEditline && useEditline) { // System.out.println ("used editline:"); line = readlineImpl(prompt); if (line != null) { addToHistory(line); } } else { // This code is never used unless the native readline // isn't available System.out.print(prompt); if (_reader == null) { _reader = new BufferedReader(new InputStreamReader(System.in)); } line = _reader.readLine(); if (line == null) { throw new EOFException("end-of-file"); } if (line.length() == 0) { line = null; } } _timeout.reset(); } catch (InterruptedException e) { System.out.println("Connection timed out: " + e.getMessage()); } return line; }