/** * Peeks to see if there is a byte waiting in the input stream without * actually consuming the byte. * * @param timeout The amount of time to wait, 0 == forever * @return -1 on eof, -2 if the timeout expired with no available input * or the character that was read (without consuming it). * @throws IOException if anything wrong happens */ public int peek(long timeout) throws IOException { return read(timeout, true); }
public int peekCharacter(long timeout) { if (!pushBackChar.isEmpty()) { return pushBackChar.peek(); } try { return reader.peek(timeout); } catch (IOException e) { throw new IOError(e); } }
/** * Close the jLine terminal when needed * * @throws IOException when closing failed */ public static void close() throws IOException { if (terminal != null) { terminal.reader().shutdown(); /*try { terminal.close(); } finally { terminal = null; }*/ } }
@Override public void close() throws IOException { reader.close(); }
@Override public int available() { return (int) (reader.available() * this.encoder.averageBytesPerChar()) + bytes.remaining(); }
@Override public void close() throws IOException { super.close(); reader.close(); }
/** * Attempts to read a character from the input stream for a specific * period of time. * * @param timeout The amount of time to wait for the character * @return The character read, -1 if EOF is reached, or -2 if the * read timed out. * @throws IOException if anything wrong happens */ public int read(long timeout) throws IOException { return read(timeout, false); }
msg.append(" ").append(buffer); } else if (bindingReader.getCurrentBuffer().length() > 0 && terminal.reader().peek(1) == NonBlockingReader.READ_EXPIRED) { msg.append(" ").append(printable(bindingReader.getCurrentBuffer())); } else if (message != null) {
@Override public void close() throws IOException { ShutdownHooks.remove(closer); for (Map.Entry<Signal, Object> entry : nativeHandlers.entrySet()) { Signals.unregister(entry.getKey().name(), entry.getValue()); } super.close(); // Do not call reader.close() reader.shutdown(); }
public void close() throws IOException { super.close(); try { slaveReader.close(); } finally { try { slaveInputPipe.close(); } finally { try { } finally { slaveWriter.close(); } } } }
@Override public int read() throws IOException { return read(0L, false); }
msg.append(" ").append(buffer); } else if (bindingReader.getCurrentBuffer().length() > 0 && terminal.reader().peek(1) == NonBlockingReader.READ_EXPIRED) { msg.append(" ").append(printable(bindingReader.getCurrentBuffer())); } else if (message != null) {
public void close() throws IOException { super.close(); closing = true; pump.interrupt(); ShutdownHooks.remove(closer); for (Map.Entry<Signal, Object> entry : nativeHandlers.entrySet()) { Signals.unregister(entry.getKey().name(), entry.getValue()); } reader.close(); writer.close(); setConsoleMode(originalConsoleMode); }
/** * This version of read() is very specific to jline's purposes, it * will always always return a single byte at a time, rather than filling * the entire buffer. * @param b the buffer * @param off the offset in the buffer * @param len the maximum number of chars to read * @throws IOException if anything wrong happens */ @Override public int read(char[] b, int off, int len) throws IOException { if (b == null) { throw new NullPointerException(); } else if (off < 0 || len < 0 || len > b.length - off) { throw new IndexOutOfBoundsException(); } else if (len == 0) { return 0; } int c = this.read(0L); if (c == EOF) { return EOF; } b[off] = (char) c; return 1; }
private int getUserAnswer(String question, int... allowedAnswers) throws IOException { final Set<Integer> allowedAnswerSet = IntStream.of(allowedAnswers).boxed().collect(Collectors.toSet()); final Terminal terminal = sqlLine.getLineReader().getTerminal(); final PrintWriter writer = terminal.writer(); writer.write(question); int c; // The logic to prevent reaction of SqlLineParser here do { c = terminal.reader().read(100); } while (c != -1 && !allowedAnswerSet.contains(c)); return c; }
start = System.currentTimeMillis(); int c = reader.read(timeout); if (c == EOF) { return EOF;
/** * Read a codepoint from the terminal. * * @return the character, or -1 if an EOF is received. */ public int readCharacter() { if (!pushBackChar.isEmpty()) { return pushBackChar.pop(); } try { int c = NonBlockingReader.READ_EXPIRED; int s = 0; while (c == NonBlockingReader.READ_EXPIRED) { c = reader.read(100L); if (c >= 0 && Character.isHighSurrogate((char) c)) { s = c; c = NonBlockingReader.READ_EXPIRED; } } return s != 0 ? Character.toCodePoint((char) s, (char) c) : c; } catch (ClosedException e) { throw new EndOfFileException(e); } catch (IOException e) { throw new IOError(e); } }
int start = 0; while (true) { int c = terminal.reader().read(); if (c < 0) { return null;
@Override public Object execute() throws Exception { if (arguments == null || arguments.length() == 0) { System.err.println("Argument expected"); } else { WatchTask watchTask = new WatchTask(); executorService.scheduleAtFixedRate(watchTask, 0, interval, TimeUnit.SECONDS); try { Terminal terminal = (Terminal) session.get(".jline.terminal"); Terminal.SignalHandler prev = terminal.handle(Terminal.Signal.INT, this::abort); Attributes attr = terminal.enterRawMode(); try { reading = Thread.currentThread(); while (terminal.reader().read(1) == NonBlockingReader.READ_EXPIRED); } finally { reading = null; terminal.setAttributes(attr); terminal.handle(Terminal.Signal.INT, prev); } } catch (InterruptedIOException e) { // Ignore } finally { abort = true; executorService.shutdownNow(); } } return null; }
@Override public Object execute() throws Exception { if (arguments == null || arguments.length() == 0) { System.err.println("Argument expected"); } else { WatchTask watchTask = new WatchTask(); executorService.scheduleAtFixedRate(watchTask, 0, interval, TimeUnit.SECONDS); try { Terminal terminal = (Terminal) session.get(".jline.terminal"); Terminal.SignalHandler prev = terminal.handle(Terminal.Signal.INT, this::abort); Attributes attr = terminal.enterRawMode(); try { reading = Thread.currentThread(); while (terminal.reader().read(1) == NonBlockingReader.READ_EXPIRED); } finally { reading = null; terminal.setAttributes(attr); terminal.handle(Terminal.Signal.INT, prev); } } catch (InterruptedIOException e) { // Ignore } finally { abort = true; executorService.shutdownNow(); } } return null; }