Class NonBlockingInputStream

    • Constructor Detail

      • NonBlockingInputStream

        public NonBlockingInputStream()
    • Method Detail

      • read

        public int read()
                 throws IOException
        Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.
        Specified by:
        read in class InputStream
        Returns:
        the next byte of data, or -1 if the end of the stream is reached.
        Throws:
        IOException - if an I/O error occurs.
      • 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 an I/O error occurs.
      • 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 an I/O error occurs.
      • shutdown

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