Code example for StringTokenizer

Methods: countTokensnextToken

0
         errorCode = ERR_PROTOCOL_INCORRECT;
         errorMessage = "Identd server closed connection.";
         return; 
      } 
 
      StringTokenizer st = new StringTokenizer(response,":");
      if(st.countTokens() < 3){
         errorCode = ERR_PROTOCOL_INCORRECT;
         errorMessage = "Can't parse server response.";
         return; 
      } 
 
      st.nextToken(); //Discard first token, it's basically what we have send
      String command = st.nextToken().trim().toUpperCase();
 
      if(command.equals("USERID") && st.countTokens() >= 2){
        successful = true;
        hostType = st.nextToken().trim();
        userName = st.nextToken("").substring(1);//Get all that is left
      }else if(command.equals("ERROR")){
        errorCode = ERR_PROTOCOL;
        errorMessage = st.nextToken();
      }else{ 
        errorCode = ERR_PROTOCOL_INCORRECT;
        System.out.println("Opa!");
        errorMessage = "Can't parse server response.";
      } 
Connect your IDE to all the code out there  Get Codota for Java