code: private String getLine(CharBuffer cb) {
          String line = null;
          int pos = cb.position();
          int limit = cb.limit();
          cb.flip();
          for (int i = 0; i < cb.length(); i++) {
              if (cb.charAt(i) == '\n') {
                  line = getSubSequence(cb, 0, i).toString();
                  cb.position(i + 1);
                  break;
              }
          }
          if (line != null) {
              cb.compact();
              if (eventBuffer != null) {
                  eventBuffer.append(line);
                  String eventString = eventBuffer.toString();
                  eventBuffer = null;
                  line = eventString;
              }
              line.trim();
          } else {
              if (cb.length() > 0) {
                  if (cb.length() == cb.capacity()) {
                      if (eventBuffer == null) {
                          logger.debug("Encountered big event.");
                          eventBuffer = new StringBuilder();
                      }
                      eventBuffer.append(getSubSequence(cb, 0, pos));
                  } else {
                      cb.position(pos);
                      cb.limit(limit);
                  }
              } else {
                  cb.clear();
              }
          }
          return line;
      }
docs: Offers lines in buffer to queue.
  
  @param cb a buffer to have received text data.
  @return the line string. null if no EOL, otherwise buffer is compacted.