private void readerThread() {
    boolean done = false;
    char[] readBuffer = new char[128];

    while (!done && !stopThreads.get()) {
      try {
        int n = inputStream.available();
        if (n > 0) {
          if (readBuffer.length < n) {
            readBuffer = new char[readBuffer.length * 2];
          }

          int rc = input.read(readBuffer, 0, readBuffer.length);
          if (rc == -1) {
            // EOF
            done = true;
          } else {
            for (int i = 0; i < rc; i++) {
              int ch = readBuffer[i];
              inputCharacterQueue.offer((char) ch);
            }
          }
        } else {
          Thread.sleep(20);
        }
      } catch (InterruptedException e) {
        // Restore interrupt status
        Thread.currentThread().interrupt();
        done = true;
      } catch (IOException e) {
        LOGGER.error("Caught an exception", e);
        done = true;
      }
    }
  }
This generates {@link KeyPress} objects from the given input stream and offers them to the given
queue.
hbase-hbtop/src/main/java/org/apache/hadoop/hbase/hbtop/terminal/impl/KeyPressGenerator.java