java.io.StreamTokenizer
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
|
|
|
Value |
|
int |
TT_EOF |
The constant representing end of stream. |
-1 |
0xffffffff |
int |
TT_EOL |
The constant representing end of line. |
10 |
0x0000000a |
int |
TT_NUMBER |
The constant representing a number token. |
-2 |
0xfffffffe |
int |
TT_WORD |
The constant representing a word token. |
-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 Methods
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait
Details
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
)
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.
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.
|