code: public CommandEvent readEvent(int timeout, TimeUnit unit) throws Exception {
  
          checkConnected();
  
          connection.setReadTimeout((int) unit.toMillis(timeout));
  
          CommandEvent event = null;
          String eventType = textIn.readLine();
  
          if (Thread.interrupted())
          {
              throw new InterruptedException("thread interrupted during blocking read");
          }
  
          if (eventType != null) {
              switch (eventType) {
              case PREPARED_EVENT:
                  event = readPreparedEvent();
                  break;
              case STARTED_EVENT:
                  event = readStartedEvent();
                  break;
              case ERROR_EVENT:
                  event = readErrorEvent();
                  break;
              case FINISHED_EVENT:
                  event = readFinishedEvent();
                  break;
              case NOTIFIED_EVENT:
                  event = readNotifiedEvent();
                  break;
              default:
                  throw new IllegalStateException("Invalid protocol frame: " + eventType);
              }
          }
  
          return event;
      }
docs: Reads a command event from the wire.
  @param timeout is the time to read from the connection.
  @param unit of time for the timeout.
  @return the CommandEvent read from the wire.
  @throws Exception if no event is read before the timeout.