use of java.io.StreamTokenizer in project gephi by gephi.
the class ImporterDOT method importData.
private void importData(LineNumberReader reader) throws Exception {
Progress.start(progressTicket);
StreamTokenizer streamTokenizer = new StreamTokenizer(reader);
setSyntax(streamTokenizer);
graph(streamTokenizer);
}
use of java.io.StreamTokenizer in project XobotOS by xamarin.
the class TypedProperties method parse.
/**
* Parses the data in the reader.
*
* @param r The {@code Reader} containing input data to parse
* @param map The {@code Map} to insert parameter values into
* @throws ParseException if the input data is malformed
* @throws IOException if there is a problem reading from the {@code Reader}
*/
static void parse(Reader r, Map<String, Object> map) throws ParseException, IOException {
final StreamTokenizer st = initTokenizer(r);
/* A property name must be a valid fully-qualified class + package name.
* We don't support Unicode, though.
*/
final String identifierPattern = "[a-zA-Z_$][0-9a-zA-Z_$]*";
final Pattern propertyNamePattern = Pattern.compile("(" + identifierPattern + "\\.)*" + identifierPattern);
while (true) {
int token;
// Read the next token, which is either the type or EOF.
token = st.nextToken();
if (token == StreamTokenizer.TT_EOF) {
break;
}
if (token != StreamTokenizer.TT_WORD) {
throw new ParseException(st, "type name");
}
final int type = interpretType(st.sval);
if (type == TYPE_ERROR) {
throw new ParseException(st, "valid type name");
}
st.sval = null;
if (type == TYPE_UNSET) {
// Expect '('.
token = st.nextToken();
if (token != '(') {
throw new ParseException(st, "'('");
}
}
// Read the property name.
token = st.nextToken();
if (token != StreamTokenizer.TT_WORD) {
throw new ParseException(st, "property name");
}
final String propertyName = st.sval;
if (!propertyNamePattern.matcher(propertyName).matches()) {
throw new ParseException(st, "valid property name");
}
st.sval = null;
if (type == TYPE_UNSET) {
// Expect ')'.
token = st.nextToken();
if (token != ')') {
throw new ParseException(st, "')'");
}
map.remove(propertyName);
} else {
// Expect '='.
token = st.nextToken();
if (token != '=') {
throw new ParseException(st, "'='");
}
// Read a value of the appropriate type, and insert into the map.
final Object value = parseValue(st, type);
final Object oldValue = map.remove(propertyName);
if (oldValue != null) {
// the same property is defined with a different type.
if (value.getClass() != oldValue.getClass()) {
throw new ParseException(st, "(property previously declared as a different type)");
}
}
map.put(propertyName, value);
}
// Expect ';'.
token = st.nextToken();
if (token != ';') {
throw new ParseException(st, "';'");
}
}
}
use of java.io.StreamTokenizer in project platform_frameworks_base by android.
the class TypedProperties method parse.
/**
* Parses the data in the reader.
*
* @param r The {@code Reader} containing input data to parse
* @param map The {@code Map} to insert parameter values into
* @throws ParseException if the input data is malformed
* @throws IOException if there is a problem reading from the {@code Reader}
*/
static void parse(Reader r, Map<String, Object> map) throws ParseException, IOException {
final StreamTokenizer st = initTokenizer(r);
/* A property name must be a valid fully-qualified class + package name.
* We don't support Unicode, though.
*/
final String identifierPattern = "[a-zA-Z_$][0-9a-zA-Z_$]*";
final Pattern propertyNamePattern = Pattern.compile("(" + identifierPattern + "\\.)*" + identifierPattern);
while (true) {
int token;
// Read the next token, which is either the type or EOF.
token = st.nextToken();
if (token == StreamTokenizer.TT_EOF) {
break;
}
if (token != StreamTokenizer.TT_WORD) {
throw new ParseException(st, "type name");
}
final int type = interpretType(st.sval);
if (type == TYPE_ERROR) {
throw new ParseException(st, "valid type name");
}
st.sval = null;
if (type == TYPE_UNSET) {
// Expect '('.
token = st.nextToken();
if (token != '(') {
throw new ParseException(st, "'('");
}
}
// Read the property name.
token = st.nextToken();
if (token != StreamTokenizer.TT_WORD) {
throw new ParseException(st, "property name");
}
final String propertyName = st.sval;
if (!propertyNamePattern.matcher(propertyName).matches()) {
throw new ParseException(st, "valid property name");
}
st.sval = null;
if (type == TYPE_UNSET) {
// Expect ')'.
token = st.nextToken();
if (token != ')') {
throw new ParseException(st, "')'");
}
map.remove(propertyName);
} else {
// Expect '='.
token = st.nextToken();
if (token != '=') {
throw new ParseException(st, "'='");
}
// Read a value of the appropriate type, and insert into the map.
final Object value = parseValue(st, type);
final Object oldValue = map.remove(propertyName);
if (oldValue != null) {
// the same property is defined with a different type.
if (value.getClass() != oldValue.getClass()) {
throw new ParseException(st, "(property previously declared as a different type)");
}
}
map.put(propertyName, value);
}
// Expect ';'.
token = st.nextToken();
if (token != ';') {
throw new ParseException(st, "';'");
}
}
}
use of java.io.StreamTokenizer in project robovm by robovm.
the class OldStreamTokenizerTest method test_harmonyRegressionTest.
public void test_harmonyRegressionTest() {
byte[] data = new byte[] { (byte) '-' };
StreamTokenizer tokenizer = new StreamTokenizer(new ByteArrayInputStream(data));
try {
tokenizer.nextToken();
} catch (Exception e) {
Assert.fail(e.getMessage());
}
String result = tokenizer.toString();
Assert.assertEquals("Token['-'], line 1", result);
}
use of java.io.StreamTokenizer in project robovm by robovm.
the class OldStreamTokenizerTest method test_nextToken.
public void test_nextToken() throws IOException {
st = new StreamTokenizer(new Support_StringReader("\n \r\n#"));
// make \n ordinary
st.ordinaryChar('\n');
st.eolIsSignificant(true);
assertTrue("Wrong token 2,1", st.nextToken() == '\n');
assertTrue("Wrong token 2,2", st.nextToken() == '\n');
assertEquals("Wrong token 2,3", '#', st.nextToken());
Support_ASimpleInputStream sis = new Support_ASimpleInputStream();
sis.throwExceptionOnNextUse = true;
st = new StreamTokenizer(sis);
try {
st.nextToken();
fail("IOException expected.");
} catch (IOException e) {
// Expected.
}
}
Aggregations