StreamTokenizer
class takes an input stream and
parses it into "tokens", allowing the tokens to be
read one at a time. The parsing process is controlled by a table
and a number of flags that can be set to various states. The
stream tokenizer can recognize identifiers, numbers, quoted
strings, and various comment styles.
Each byte read from the input stream is regarded as a character
in the range '\u0000'
through '\u00FF'
.
The character value is used to look up five possible attributes of
the character: white space, alphabetic,
numeric, string quote, and comment character.
Each character can have zero or more of these attributes.
In addition, an instance has four flags. These flags indicate:
A typical application first constructs an instance of this class,
sets up the syntax tables, and then repeatedly loops calling the
nextToken
method in each iteration of the loop until
it returns the value TT_EOF
.
java.io.StreamTokenizer#nextToken()
, java.io.StreamTokenizer#TT_EOF
Modifier and Type | Field and Description |
---|---|
private char[] | |
private static final byte | |
private static final byte | |
private static final byte | |
private static final byte | |
private static final byte | |
private final byte[] | |
private boolean | |
private boolean | |
private InputStream | |
private int | LINENO
The line number of the last token read |
private static final int | |
public double | nval
If the current token is a number, this field contains the value of that number. |
private int | peekc
The next character to be considered by the nextToken method. |
private boolean | |
private Reader | |
private static final int | |
private boolean | |
private boolean | |
public String | sval
If the current token is a word token, this field contains a string giving the characters of the word token. |
public static final int | TT_EOF
A constant indicating that the end of the stream has been read. |
public static final int | TT_EOL
A constant indicating that the end of the line has been read. |
private static final int | |
public static final int | TT_NUMBER
A constant indicating that a number token has been read. |
public static final int | TT_WORD
A constant indicating that a word token has been read. |
public int | ttype
After a call to the |
Access | Constructor and Description |
---|---|
private | |
public | StreamTokenizer(InputStream
an input stream. is)
Deprecated
As of JDK version 1.1, the preferred way to tokenize an
input stream is to convert it into a character stream, for example:
Reader r = new BufferedReader(new InputStreamReader(is)); StreamTokenizer st = new StreamTokenizer(r); Creates a stream tokenizer that parses the specified input stream. |
public | StreamTokenizer(Reader
a Reader object providing the input stream. r)Create a tokenizer that parses the given character stream. |
Modifier and Type | Method and Description |
---|---|
public void | commentChar(int
the character. ch)Specifies that the character argument starts a single-line comment. |
public void | eolIsSignificant(boolean
true indicates that end-of-line characters
are separate tokens; false indicates that
end-of-line characters are white space.Determines whether or not ends of line are treated as tokens. |
public int | |
public void | lowerCaseMode(boolean
true indicates that all word tokens should
be lowercased.Determines whether or not word token are automatically lowercased. |
public int | Returns: the value of thettype field.Parses the next token from the input stream of this tokenizer. |
public void | ordinaryChar(int
the character. ch)Specifies that the character argument is "ordinary" in this tokenizer. |
public void | ordinaryChars(int
the low end of the range. low, int the high end of the range. hi)Specifies that all characters c in the range
|
public void | |
public void | pushBack()
Causes the next call to the |
public void | quoteChar(int
the character. ch)Specifies that matching pairs of this character delimit string constants in this tokenizer. |
private int | |
public void | resetSyntax()
Resets this tokenizer's syntax table so that all characters are
"ordinary." See the |
public void | slashSlashComments(boolean
true indicates to recognize and ignore
C++-style comments.Determines whether or not the tokenizer recognizes C++-style comments. |
public void | slashStarComments(boolean
true indicates to recognize and ignore
C-style comments.Determines whether or not the tokenizer recognizes C-style comments. |
public String | Returns: a string representation of the tokenOverrides java. Returns the string representation of the current stream token and the line number it occurs on. |
public void | whitespaceChars(int
the low end of the range. low, int the high end of the range. hi)Specifies that all characters c in the range
|
public void | wordChars(int
the low end of the range. low, int the high end of the range. hi)Specifies that all characters c in the range
|
buf | back to summary |
---|---|
private char[] buf |
CT_ALPHA | back to summary |
---|---|
private static final byte CT_ALPHA |
CT_COMMENT | back to summary |
---|---|
private static final byte CT_COMMENT |
CT_DIGIT | back to summary |
---|---|
private static final byte CT_DIGIT |
CT_QUOTE | back to summary |
---|---|
private static final byte CT_QUOTE |
CT_WHITESPACE | back to summary |
---|---|
private static final byte CT_WHITESPACE |
ctype | back to summary |
---|---|
private final byte[] ctype |
eolIsSignificantP | back to summary |
---|---|
private boolean eolIsSignificantP |
forceLower | back to summary |
---|---|
private boolean forceLower |
input | back to summary |
---|---|
private InputStream input |
LINENO | back to summary |
---|---|
private int LINENO The line number of the last token read |
NEED_CHAR | back to summary |
---|---|
private static final int NEED_CHAR |
nval | back to summary |
---|---|
public double nval If the current token is a number, this field contains the value
of that number. The current token is a number when the value of
the The initial value of this field is 0.0. |
peekc | back to summary |
---|---|
private int peekc The next character to be considered by the nextToken method. May also be NEED_CHAR to indicate that a new character should be read, or SKIP_LF to indicate that a new character should be read and, if it is a '\n' character, it should be discarded and a second new character should be read. |
pushedBack | back to summary |
---|---|
private boolean pushedBack |
reader | back to summary |
---|---|
private Reader reader |
SKIP_LF | back to summary |
---|---|
private static final int SKIP_LF |
slashSlashCommentsP | back to summary |
---|---|
private boolean slashSlashCommentsP |
slashStarCommentsP | back to summary |
---|---|
private boolean slashStarCommentsP |
sval | back to summary |
---|---|
public String sval If the current token is a word token, this field contains a string giving the characters of the word token. When the current token is a quoted string token, this field contains the body of the string.
The current token is a word when the value of the
The initial value of this field is null. |
TT_EOF | back to summary |
---|---|
public static final int TT_EOF A constant indicating that the end of the stream has been read. |
TT_EOL | back to summary |
---|---|
public static final int TT_EOL A constant indicating that the end of the line has been read. |
TT_NOTHING | back to summary |
---|---|
private static final int TT_NOTHING |
TT_NUMBER | back to summary |
---|---|
public static final int TT_NUMBER A constant indicating that a number token has been read. |
TT_WORD | back to summary |
---|---|
public static final int TT_WORD A constant indicating that a word token has been read. |
ttype | back to summary |
---|---|
public int ttype After a call to the
The initial value of this field is -4. |
StreamTokenizer | back to summary |
---|---|
private StreamTokenizer() Private constructor that initializes everything except the streams. |
StreamTokenizer | back to summary |
---|---|
public StreamTokenizer(InputStream is)
Deprecated As of JDK version 1.1, the preferred way to tokenize an input stream is to convert it into a character stream, for example: Reader r = new BufferedReader(new InputStreamReader(is)); StreamTokenizer st = new StreamTokenizer(r); Creates a stream tokenizer that parses the specified input stream. The stream tokenizer is initialized to the following default state:
|
StreamTokenizer | back to summary |
---|---|
public StreamTokenizer(Reader r) Create a tokenizer that parses the given character stream.
|
commentChar | back to summary |
---|---|
public void commentChar(int ch) Specifies that the character argument starts a single-line comment. All characters from the comment character to the end of the line are ignored by this stream tokenizer. Any other attribute settings for the specified character are cleared.
|
eolIsSignificant | back to summary |
---|---|
public void eolIsSignificant(boolean flag) Determines whether or not ends of line are treated as tokens.
If the flag argument is true, this tokenizer treats end of lines
as tokens; the
A line is a sequence of characters ending with either a
carriage-return character (
If the
|
lineno | back to summary |
---|---|
public int lineno() Returns the current line number.
|
lowerCaseMode | back to summary |
---|---|
public void lowerCaseMode(boolean fl) Determines whether or not word token are automatically lowercased.
If the flag argument is
If the flag argument is
|
nextToken | back to summary |
---|---|
public int nextToken() throws IOException Parses the next token from the input stream of this tokenizer.
The type of the next token is returned in the Typical clients of this class first set up the syntax tables and then sit in a loop calling nextToken to parse successive tokens until TT_EOF is returned.
|
ordinaryChar | back to summary |
---|---|
public void ordinaryChar(int ch) Specifies that the character argument is "ordinary"
in this tokenizer. It removes any special significance the
character has as a comment character, word component, string
delimiter, white space, or number character. When such a character
is encountered by the parser, the parser treats it as a
single-character token and sets Making a line terminator character "ordinary" may interfere
with the ability of a
|
ordinaryChars | back to summary |
---|---|
public void ordinaryChars(int low, int hi) Specifies that all characters c in the range
|
parseNumbers | back to summary |
---|---|
public void parseNumbers() Specifies that numbers should be parsed by this tokenizer. The syntax table of this tokenizer is modified so that each of the twelve characters: 0 1 2 3 4 5 6 7 8 9 . - has the "numeric" attribute.
When the parser encounters a word token that has the format of a
double precision floating-point number, it treats the token as a
number rather than a word, by setting the |
pushBack | back to summary |
---|---|
public void pushBack() Causes the next call to the |
quoteChar | back to summary |
---|---|
public void quoteChar(int ch) Specifies that matching pairs of this character delimit string constants in this tokenizer.
When the
If a string quote character is encountered, then a string is
recognized, consisting of all characters after (but not including)
the string quote character, up to (but not including) the next
occurrence of that same string quote character, or a line
terminator, or end of file. The usual escape sequences such as
Any other attribute settings for the specified character are cleared.
|
read | back to summary |
---|---|
private int read() throws IOException Read the next character |
resetSyntax | back to summary |
---|---|
public void resetSyntax() Resets this tokenizer's syntax table so that all characters are
"ordinary." See the |
slashSlashComments | back to summary |
---|---|
public void slashSlashComments(boolean flag) Determines whether or not the tokenizer recognizes C++-style comments.
If the flag argument is
If the flag argument is
|
slashStarComments | back to summary |
---|---|
public void slashStarComments(boolean flag) Determines whether or not the tokenizer recognizes C-style comments.
If the flag argument is
If the flag argument is
|
toString | back to summary |
---|---|
public String toString() Overrides java. Returns the string representation of the current stream token and the line number it occurs on. The precise string returned is unspecified, although the following example can be considered typical: Token['a'], line 10
|
whitespaceChars | back to summary |
---|---|
public void whitespaceChars(int low, int hi) Specifies that all characters c in the range
Any other attribute settings for the characters in the specified range are cleared.
|
wordChars | back to summary |
---|---|
public void wordChars(int low, int hi) Specifies that all characters c in the range
|