Code example for StreamTokenizer

Methods: linenonextTokenpushBack

0
        return pos;
    } 
 
 
    private boolean isNumberNext(StreamTokenizer tokenizer) throws IOException {
        int type = tokenizer.nextToken();
        tokenizer.pushBack();
        return type == StreamTokenizer.TT_WORD;
    } 
 
    /** 
     * Parses the next number in the stream. 
     * Numbers with exponents are handled. 
     * 
     * @param tokenizer tokenizer over a stream of text in Well-known Text 
     *                  format. The next token must be a number. 
     * @return the next number in the stream 
     * @throws ParseException if the next token is not a valid number 
     * @throws IOException    if an I/O error occurs 
     */ 
    private double getNextNumber(StreamTokenizer tokenizer) throws IOException,
            ParseException { 
        int type = tokenizer.nextToken();
        switch (type) {
            case StreamTokenizer.TT_WORD: {
                try { 
                    return Double.parseDouble(tokenizer.sval);
                } catch (NumberFormatException ex) {
                    throw new ParseException("Invalid number: " + tokenizer.sval, tokenizer.lineno());
                } 
            } 
            default: 
        } 
        parseError("number", tokenizer);