code: public static int getTokenCount(final Buffer buffer) throws IndexOutOfBoundsException, IOException {
          boolean done = false;
          int count = 0;
          buffer.markReaderIndex();
          while (buffer.hasReadableBytes() && !done) {
              final byte b = buffer.readByte();
              final boolean ok = isAlphaNum(b) || b == DASH || b == PERIOD || b == EXCLAMATIONPOINT
                      || b == PERCENT || b == STAR || b == UNDERSCORE || b == PLUS || b == BACKTICK
                      || b == TICK || b == TILDE;
              if (ok) {
                  ++count;
              } else {
                  done = true;
              }
          }
          buffer.resetReaderIndex();
          return count;
      }
docs: Helper method that counts the number of bytes that are considered part of
  the next token in the {@link Buffer}.
  
  @param buffer
  @return a count of the number of bytes the next token contains or zero if
  no token is to be found within the buffer.
  @throws IOException
  @throws IndexOutOfBoundsException