public class StreamTokenizer extends Object
| Modifier and Type | Field and Description |
|---|---|
double |
nval
Contains a number if the current token is a number (
ttype ==
TT_NUMBER). |
String |
sval
Contains a string if the current token is a word (
ttype ==
TT_WORD). |
static int |
TT_EOF
The constant representing the end of the stream.
|
static int |
TT_EOL
The constant representing the end of the line.
|
static int |
TT_NUMBER
The constant representing a number token.
|
static int |
TT_WORD
The constant representing a word token.
|
int |
ttype
After calling
nextToken(), ttype contains the type of
token that has been read. |
| Constructor and Description |
|---|
StreamTokenizer(InputStream is)
Deprecated.
Use
StreamTokenizer(Reader) instead. |
StreamTokenizer(Reader r)
Constructs a new
StreamTokenizer with r as source reader. |
| Modifier and Type | Method and Description |
|---|---|
void |
commentChar(int ch)
Specifies that the character
ch shall be treated as a comment
character. |
void |
eolIsSignificant(boolean flag)
Specifies whether the end of a line is significant and should be returned
as
TT_EOF in ttype by this tokenizer. |
int |
lineno()
Returns the current line number.
|
void |
lowerCaseMode(boolean flag)
Specifies whether word tokens should be converted to lower case when they
are stored in
sval. |
int |
nextToken()
Parses the next token from this tokenizer's source stream or reader.
|
void |
ordinaryChar(int ch)
Specifies that the character
ch shall be treated as an ordinary
character by this tokenizer. |
void |
ordinaryChars(int low,
int hi)
Specifies that the characters in the range from
low to hi
shall be treated as an ordinary character by this tokenizer. |
void |
parseNumbers()
Specifies that this tokenizer shall parse numbers.
|
void |
pushBack()
Indicates that the current token should be pushed back and returned again
the next time
nextToken() is called. |
void |
quoteChar(int ch)
Specifies that the character
ch shall be treated as a quote
character. |
void |
resetSyntax()
Specifies that all characters shall be treated as ordinary characters.
|
void |
slashSlashComments(boolean flag)
Specifies whether "slash-slash" (C++-style) comments shall be recognized.
|
void |
slashStarComments(boolean flag)
Specifies whether "slash-star" (C-style) comments shall be recognized.
|
String |
toString()
Returns the state of this tokenizer in a readable format.
|
void |
whitespaceChars(int low,
int hi)
Specifies that the characters in the range from
low to hi
shall be treated as whitespace characters by this tokenizer. |
void |
wordChars(int low,
int hi)
Specifies that the characters in the range from
low to hi
shall be treated as word characters by this tokenizer. |
public double nval
ttype ==
TT_NUMBER).public String sval
ttype ==
TT_WORD).public static final int TT_EOF
public static final int TT_EOL
public static final int TT_NUMBER
public static final int TT_WORD
public int ttype
nextToken(), ttype contains the type of
token that has been read. When a single character is read, its value
converted to an integer is stored in ttype. For a quoted string,
the value is the quoted character. Otherwise, its value is one of the
following:
TT_WORD - the token is a word.TT_NUMBER - the token is a number.TT_EOL - the end of line has been reached. Depends on
whether eolIsSignificant is true.TT_EOF - the end of the stream has been reached.@Deprecated public StreamTokenizer(InputStream is)
StreamTokenizer(Reader) instead.StreamTokenizer with is as source input
stream. This constructor is deprecated; instead, the constructor that
takes a Reader as an argument should be used.is - the source stream from which to parse tokens.NullPointerException - if is is null.public StreamTokenizer(Reader r)
StreamTokenizer with r as source reader.
The tokenizer's initial state is as follows:
r - the source reader from which to parse tokens.public void commentChar(int ch)
ch shall be treated as a comment
character.ch - the character to be considered a comment character.public void eolIsSignificant(boolean flag)
TT_EOF in ttype by this tokenizer.flag - true if EOL is significant, false otherwise.public int lineno()
public void lowerCaseMode(boolean flag)
sval.flag - true if sval should be converted to lower
case, false otherwise.public int nextToken()
throws IOException
ttype field, additional
information may be stored in the nval or sval fields.ttype.IOException - if an I/O error occurs while parsing the next token.public void ordinaryChar(int ch)
ch shall be treated as an ordinary
character by this tokenizer. That is, it has no special meaning as a
comment character, word component, white space, string delimiter or
number.ch - the character to be considered an ordinary character.public void ordinaryChars(int low,
int hi)
low to hi
shall be treated as an ordinary character by this tokenizer. That is,
they have no special meaning as a comment character, word component,
white space, string delimiter or number.low - the first character in the range of ordinary characters.hi - the last character in the range of ordinary characters.public void parseNumbers()
public void pushBack()
nextToken() is called.public void quoteChar(int ch)
ch shall be treated as a quote
character.ch - the character to be considered a quote character.public void resetSyntax()
public void slashSlashComments(boolean flag)
flag - true if // should be recognized as the start
of a comment, false otherwise.public void slashStarComments(boolean flag)
flag - true if /* should be recognized as the start
of a comment, false otherwise.public String toString()
public void whitespaceChars(int low,
int hi)
low to hi
shall be treated as whitespace characters by this tokenizer.low - the first character in the range of whitespace characters.hi - the last character in the range of whitespace characters.public void wordChars(int low,
int hi)
low to hi
shall be treated as word characters by this tokenizer. A word consists of
a word character followed by zero or more word or number characters.low - the first character in the range of word characters.hi - the last character in the range of word characters.