Code example for StringTokenizer

Methods: countTokens, nextToken

0
			errorCode = ERR_PROTOCOL_INCORRECT;
			errorMessage = "Identd server closed connection.";
			return; 
		} 
 
		final 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
		final 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.";
		}