code: protected String consumeWord(ImapRequestLineReader request,
                                   CharacterValidator validator)
              throws ProtocolException {
          StringBuilder atom = new StringBuilder();
  
          char next = request.nextWordChar();
          while (!isWhitespace(next)) {
              if (validator.isValid(next)) {
                  atom.append(next);
                  request.consume();
              } else {
                  throw new ProtocolException("Invalid character: '" + next + '\'');
              }
              next = request.nextChar();
          }
          return atom.toString();
      }
docs: Reads the next "word from the request, comprising all characters up to the next SPACE.
  Characters are tested by the supplied CharacterValidator, and an exception is thrown
  if invalid characters are encountered.