Class NonBlockingReader

    • Constructor Detail

      • NonBlockingReader

        public NonBlockingReader()
    • Method Detail

      • shutdown

        public void shutdown()
        Shuts down the thread that is handling blocking I/O. Note that if the thread is currently blocked waiting for I/O it will not actually shut down until the I/O is received.
      • peek

        public int peek​(long timeout)
                 throws IOException
        Peeks to see if there is a byte waiting in the input stream without actually consuming the byte.
        Parameters:
        timeout - The amount of time to wait, 0 == forever
        Returns:
        -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
      • read

        public int read​(long timeout)
                 throws IOException
        Attempts to read a character from the input stream for a specific period of time.
        Parameters:
        timeout - The amount of time to wait for the character
        Returns:
        The character read, -1 if EOF is reached, or -2 if the read timed out.
        Throws:
        IOException - if anything wrong happens
      • read

        public int read​(char[] b,
                        int off,
                        int len)
                 throws IOException
        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.
        Specified by:
        read in class Reader
        Parameters:
        b - the buffer
        off - the offset in the buffer
        len - the maximum number of chars to read
        Throws:
        IOException - if anything wrong happens
      • available

        public int available()
      • read

        protected abstract int read​(long timeout,
                                    boolean isPeek)
                             throws IOException
        Attempts to read a character from the input stream for a specific period of time.
        Parameters:
        timeout - The amount of time to wait for the character
        isPeek - trueif the character read must not be consumed
        Returns:
        The character read, -1 if EOF is reached, or -2 if the read timed out.
        Throws:
        IOException - if anything wrong happens