code: private int checkOutput(int readBytes) throws IOException {
      if (readBytes > -1) {
        return readBytes;
      }
      if (closed) {
        throw new IOException("The stream has been closed");
      }
      if (readThread.error != null) {
        throw new IOException(readThread.error.getMessage());
      }
      return readBytes;
    }
docs: Check if the read thread died, if so, throw an exception.