Name: el35337 Date: 01/09/97
/*
Jonathan Cheyer
###@###.###
18 Dec 1996
This program demonstrates that when ascii chr(32) has its white-space
attribute removed, nextToken() does not work correctly.
Apparently, chr(32) was hard-coded into the nextToken() method to be
used as a character that is "guaranteed" to have the white-space
attribute set on.
This program should wait for input from stdin and return the first
token.
This works unless chr(32) has its white-space attribute removed. In
that
case, nextToken() returns an initial space instead of reading the next
token.
This isn't the expected behavior as described in:
Java Language Specification
Gosling, Joy, Steele
Version 1.0
Chapter 22.14: Class java.io.StreamTokenizer
http://www.javasoft.com/doc/language_specification/javaio.doc.html
*/
import java.io.StreamTokenizer;
import java.io.IOException;
public class test {
public test() {
int t;
StreamTokenizer st = new StreamTokenizer(System.in);
/* Uncommenting the line below causes nextToken() to break */
// st.ordinaryChar(32);
try {
System.out.println("ttype before calling nextToken: " + st.ttype);
t = st.nextToken();
System.out.println("ttype after calling nextToken: " + st.ttype);
if (t == StreamTokenizer.TT_WORD){
System.out.print("sval[0] = chr(" + (int) st.sval.charAt(0));
System.out.println("), sval = " + "'" + st.sval + "'");
}
}
catch (IOException e) {
System.out.println("error");
System.exit(-1);
}
}
public static void main(String argv[]) {
test temp = new test();
}
}
======================================================================
- duplicates
-
JDK-4028902 StreamTokenizer erroneously generates leading space
-
- Closed
-
-
JDK-4022254 java.io.StreamTokenizer.pushBack method ignores possible errors
-
- Closed
-
- relates to
-
JDK-1238227 java.io.StreamTokenizer.peekc is set to ' ' when an ordinaryChar is found
-
- Closed
-