加载中...
The Wayback Machine - https://sup1a9wrlpyh5li9ro.vcoronado.top/web/20090321135140/http://developer.android.com:80/reference/java/io/StreamTokenizer.html
public class

StreamTokenizer

extends Object
java.lang.Object
   ↳ java.io.StreamTokenizer

Class Overview

StreamTokenizer takes a stream and a set of tokens and parses them one at a time. The different types of tokens that can be found are numbers, identifiers, quoted strings, and different comment styles.

Summary

Constants
int TT_EOF The constant representing end of stream.
int TT_EOL The constant representing end of line.
int TT_NUMBER The constant representing a number token.
int TT_WORD The constant representing a word token.
Fields
public double nval Contains a number if the current token is a number (ttype is TT_NUMBER)
public String sval Contains a string if the current token is a word (ttype is TT_WORD)
public int ttype The token type
Public Constructors
StreamTokenizer(InputStream is)
This constructor is deprecated. Use StreamTokenizer(Reader)
StreamTokenizer(Reader r)
Construct a new StreamTokenizer on the Reader r.
Public Methods
void commentChar(int ch)
Set the character ch to be regarded as a comment character.
void eolIsSignificant(boolean flag)
Set a boolean indicating whether or not end of line is significant and should be returned as TT_EOF in ttype.
int lineno()
Answer the current line number.
void lowerCaseMode(boolean flag)
Set a boolean indicating whether or not tokens should be uppercased when present in sval.
int nextToken()
Answer the next token type.
void ordinaryChar(int ch)
Set the character ch to be regarded as an ordinary character.
void ordinaryChars(int low, int hi)
Set the characters ranging from low to hi to be regarded as ordinary characters.
void parseNumbers()
Indicate that numbers should be parsed.
void pushBack()
Indicate that the current token should be pushed back and returned the next time nextToken() is called.
void quoteChar(int ch)
Set the character ch to be regarded as a quote character.
void resetSyntax()
Reset all characters so that they are ordinary.
void slashSlashComments(boolean flag)
Set a boolean indicating whether or not slash slash comments should be recognized.
void slashStarComments(boolean flag)
Set a boolean indicating whether or not slash star comments should be recognized.
String toString()
Answer the state of this tokenizer in a readable format.
void whitespaceChars(int low, int hi)
Set the characters ranging from low to hi to be regarded as whitespace characters.
void wordChars(int low, int hi)
Set the characters ranging from low to hi to be regarded as word characters.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int TT_EOF

The constant representing end of stream.

Constant Value: -1 (0xffffffff)

public static final int TT_EOL

The constant representing end of line.

Constant Value: 10 (0x0000000a)

public static final int TT_NUMBER

The constant representing a number token.

Constant Value: -2 (0xfffffffe)

public static final int TT_WORD

The constant representing a word token.

Constant Value: -3 (0xfffffffd)

Fields

public double nval

Contains a number if the current token is a number (ttype is TT_NUMBER)

public String sval

Contains a string if the current token is a word (ttype is TT_WORD)

public int ttype

The token type

Public Constructors

public StreamTokenizer (InputStream is)

This constructor is deprecated.Use StreamTokenizer(Reader)

Construct a new StreamTokenizer on the InputStream is. This usage of this method should be replaced with the constructor which takes a Reader.

Parameters
is The InputStream to parse tokens on.

public StreamTokenizer (Reader r)

Construct a new StreamTokenizer on the Reader r. Initialize the default state per specification.

  • All byte values 'A' through 'Z', 'a' through 'z', and '\u00A0' through '\u00FF' are considered to be alphabetic.
  • All byte values '\u0000' through '\u0020' are considered to be white space. '/' is a comment character.
  • Single quote '\'' and double quote '"' are string quote characters.
  • Numbers are parsed.
  • Ends of lines are considered to be white space rather than separate tokens.
  • C-style and C++-style comments are not recognized.
These are the defaults and are not needed in constructor.
Parameters
r The InputStream to parse tokens on.

Public Methods

public void commentChar (int ch)

Set the character ch to be regarded as a comment character.

Parameters
ch The character to be considered a comment character.

public void eolIsSignificant (boolean flag)

Set a boolean indicating whether or not end of line is significant and should be returned as TT_EOF in ttype.

Parameters
flag true if EOL is significant, false otherwise.

public int lineno ()

Answer the current line number.

Returns
  • the current line number.

public void lowerCaseMode (boolean flag)

Set a boolean indicating whether or not tokens should be uppercased when present in sval.

Parameters
flag true if sval should be forced uppercase, false otherwise.

public int nextToken ()

Answer the next token type.

Returns
  • The next token to be parsed.
Throws
IOException If an IO error occurs while getting the token

public void ordinaryChar (int ch)

Set the character ch to be regarded as an ordinary character.

Parameters
ch The character to be considered an ordinary comment character.

public void ordinaryChars (int low, int hi)

Set the characters ranging from low to hi to be regarded as ordinary characters.

Parameters
low The starting range for ordinary characters.
hi The ending range for ordinary characters.

public void parseNumbers ()

Indicate that numbers should be parsed.

public void pushBack ()

Indicate that the current token should be pushed back and returned the next time nextToken() is called.

public void quoteChar (int ch)

Set the character ch to be regarded as a quote character.

Parameters
ch The character to be considered a quote comment character.

public void resetSyntax ()

Reset all characters so that they are ordinary.

public void slashSlashComments (boolean flag)

Set a boolean indicating whether or not slash slash comments should be recognized. The comment ends at a new line.

Parameters
flag true if // should be recognized as the start of a comment, false otherwise.

public void slashStarComments (boolean flag)

Set a boolean indicating whether or not slash star comments should be recognized. Slash-star comments cannot be nested and end when a star-slash combination is found.

Parameters
flag true if /* should be recognized as the start of a comment, false otherwise.

public String toString ()

Answer the state of this tokenizer in a readable format.

Returns
  • The current state of this tokenizer.

public void whitespaceChars (int low, int hi)

Set the characters ranging from low to hi to be regarded as whitespace characters.

Parameters
low The starting range for whitespace characters.
hi The ending range for whitespace characters.

public void wordChars (int low, int hi)

Set the characters ranging from low to hi to be regarded as word characters.

Parameters
low The starting range for word characters.
hi The ending range for word characters.