public Type readNextToken ( ) throws IOException { int c ; if ( currentCharacter >= 0 && ! Character . isWhitespace ( currentCharacter ) ) { //there's still a character left from the last step c = currentCharacter ; currentCharacter = - 1 ; } else { //skip whitespace characters c = skipWhitespace ( ) ; } if ( c < 0 ) { return null ; } //handle character if ( c == ' ' ) { currentTokenType = Type . START_OBJECT ; } else if ( c == ' ' ) { currentTokenType = Type . END_OBJECT ; } else if ( c == ' ' ) { currentTokenType = Type . START_ARRAY ; } else if ( c == ' ' ) { currentTokenType = Type . END_ARRAY ; } else if ( c == ' ' ) { currentTokenType = Type . COLON ; } else if ( c == ' ' ) { currentTokenType = Type . COMMA ; } else if ( c == ' ' ) { currentTokenType = Type . STRING ; } else if ( c == ' ' || ( c >= ' ' && c <= ' ' ) ) { currentTokenType = Type . NUMBER ; //the next token is a number. save the last character read because //readNumber() will need it. currentCharacter = c ; } else if ( c == ' ' ) { int c2 = r . read ( ) ; int c3 = r . read ( ) ; int c4 = r . read ( ) ; if ( c2 == ' ' && c3 == ' ' & c4 == ' ' ) { currentTokenType = Type . TRUE ; } else { currentTokenType = null ; } } else if ( c == ' ' ) { int c2 = r . read ( ) ; int c3 = r . read ( ) ; int c4 = r . read ( ) ; int c5 = r . read ( ) ; if ( c2 == ' ' && c3 == ' ' & c4 == ' ' && c5 == ' ' ) { currentTokenType = Type . FALSE ; } else { currentTokenType = null ; } } else if ( c == ' ' ) { int c2 = r . read ( ) ; int c3 = r . read ( ) ; int c4 = r . read ( ) ; if ( c2 == ' ' && c3 == ' ' & c4 == ' ' ) { currentTokenType = Type . NULL ; } else { currentTokenType = null ; } } else { currentTokenType = null ; } if ( currentTokenType == null ) { throw new IllegalStateException ( "Unrecognized token: " + ( char ) c ) ; } return currentTokenType ; }
Reads the next token from the stream