本文整理匯總了Java中java.io.StreamTokenizer.lineno方法的典型用法代碼示例。如果您正苦於以下問題:Java StreamTokenizer.lineno方法的具體用法?Java StreamTokenizer.lineno怎麽用?Java StreamTokenizer.lineno使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.io.StreamTokenizer
的用法示例。
在下文中一共展示了StreamTokenizer.lineno方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: parseBenchArgs
import java.io.StreamTokenizer; //導入方法依賴的package包/類
String[] parseBenchArgs(StreamTokenizer tokens)
throws IOException, ConfigFormatException
{
Vector vec = new Vector();
for (;;) {
switch (tokens.ttype) {
case StreamTokenizer.TT_EOF:
case StreamTokenizer.TT_EOL:
return (String[]) vec.toArray(new String[vec.size()]);
case StreamTokenizer.TT_WORD:
case '"':
vec.add(tokens.sval);
tokens.nextToken();
break;
default:
throw new ConfigFormatException("unrecognized arg token " +
"on line " + tokens.lineno());
}
}
}
示例2: parseBenchWeight
import java.io.StreamTokenizer; //導入方法依賴的package包/類
float parseBenchWeight(StreamTokenizer tokens)
throws IOException, ConfigFormatException
{
float weight;
switch (tokens.ttype) {
case StreamTokenizer.TT_WORD:
case '"':
try {
weight = Float.parseFloat(tokens.sval);
} catch (NumberFormatException e) {
throw new ConfigFormatException("illegal weight value \"" +
tokens.sval + "\" on line " + tokens.lineno());
}
tokens.nextToken();
return weight;
default:
throw new ConfigFormatException("missing weight value on line "
+ tokens.lineno());
}
}
示例3: parseBenchName
import java.io.StreamTokenizer; //導入方法依賴的package包/類
String parseBenchName(StreamTokenizer tokens)
throws IOException, ConfigFormatException
{
String name;
switch (tokens.ttype) {
case StreamTokenizer.TT_WORD:
case '"':
name = tokens.sval;
tokens.nextToken();
return name;
default:
throw new ConfigFormatException("missing benchmark name on " +
"line " + tokens.lineno());
}
}
示例4: parseBenchClass
import java.io.StreamTokenizer; //導入方法依賴的package包/類
Benchmark parseBenchClass(StreamTokenizer tokens)
throws IOException, ConfigFormatException
{
Benchmark bench;
switch (tokens.ttype) {
case StreamTokenizer.TT_WORD:
case '"':
try {
Class cls = Class.forName(tokens.sval);
bench = (Benchmark) cls.newInstance();
} catch (Exception e) {
throw new ConfigFormatException("unable to instantiate " +
"benchmark \"" + tokens.sval + "\" on line " +
tokens.lineno());
}
tokens.nextToken();
return bench;
default:
throw new ConfigFormatException("missing benchmark class " +
"name on line " + tokens.lineno());
}
}
示例5: parseMaterialStream
import java.io.StreamTokenizer; //導入方法依賴的package包/類
/**
* Parses a map of appearances parsed from the given stream.
*/
private static Map<String, Appearance> parseMaterialStream(Reader reader, URL baseUrl, Boolean useCaches)
throws IOException
{
Map<String, Appearance> appearances = new HashMap<String, Appearance>();
Appearance currentAppearance = null;
StreamTokenizer tokenizer = createTokenizer(reader);
while (tokenizer.nextToken() != StreamTokenizer.TT_EOF)
{
switch (tokenizer.ttype)
{
case StreamTokenizer.TT_WORD:
currentAppearance = parseMaterialLine(tokenizer, appearances, currentAppearance, baseUrl,
useCaches);
break;
case StreamTokenizer.TT_EOL:
break;
default:
throw new IncorrectFormatException(
"Unexpected token " + tokenizer.sval + " at row " + tokenizer.lineno());
}
}
return appearances;
}
示例6: parseInteger
import java.io.StreamTokenizer; //導入方法依賴的package包/類
/**
* Returns the integer contained in the next token.
*/
private static int parseInteger(StreamTokenizer tokenizer) throws IOException
{
if (tokenizer.nextToken() != StreamTokenizer.TT_WORD)
{
throw new IncorrectFormatException("Expected an integer at line " + tokenizer.lineno());
}
else
{
try
{
return Integer.parseInt(tokenizer.sval);
}
catch (NumberFormatException ex)
{
throw new IncorrectFormatException(
"Found " + tokenizer.sval + " instead of an integer at line " + tokenizer.lineno());
}
}
}
示例7: getNextToken
import java.io.StreamTokenizer; //導入方法依賴的package包/類
/** Delivers the next token and checks for an unexpected end of line or file. */
public static void getNextToken(StreamTokenizer tokenizer) throws IOException {
if (tokenizer.nextToken() == StreamTokenizer.TT_EOL) {
throw new IOException("unexpected end of line " + tokenizer.lineno());
}
if (tokenizer.ttype == StreamTokenizer.TT_EOF) {
throw new IOException("unexpected end of file in line " + tokenizer.lineno());
} else if (tokenizer.ttype == '\'' || tokenizer.ttype == '"') {
tokenizer.ttype = StreamTokenizer.TT_WORD;
} else if (tokenizer.ttype == StreamTokenizer.TT_WORD && tokenizer.sval.equals("?")) {
tokenizer.ttype = '?';
}
}
示例8: getNextToken
import java.io.StreamTokenizer; //導入方法依賴的package包/類
/**
* Gets next token, checking for a premature and of line.
*
* @throws IllegalStateException if it finds a premature end of line
*/
private void getNextToken(StreamTokenizer tokenizer) throws IOException, ParseException {
if (tokenizer.nextToken() == StreamTokenizer.TT_EOL) {
throw new ParseException("premature end of line", tokenizer.lineno());
}
if (tokenizer.ttype == StreamTokenizer.TT_EOF) {
throw new ParseException(PREMATURE_END_OF_FILE, tokenizer.lineno());
} else if ((tokenizer.ttype == '\'') || (tokenizer.ttype == '"')) {
tokenizer.ttype = StreamTokenizer.TT_WORD;
} else if ((tokenizer.ttype == StreamTokenizer.TT_WORD) && (tokenizer.sval.equals("?"))) {
tokenizer.ttype = '?';
}
}
示例9: parse
import java.io.StreamTokenizer; //導入方法依賴的package包/類
@Override
public ParserState parse(StreamTokenizer st) throws IOException, ParseException
{
int token = st.ttype;
while (!endOfLineOrFile(token))
{
//token 1: key
st.nextToken();
if (!endOfLineOrFile(token))
{
String key = st.sval;
//token 2: value
token = st.nextToken();
if (endOfLineOrFile(token))
{
throw new ParseException("Expected a value for metadata key: " + key, st.lineno());
}
String value = st.sval;
this.getParser().getExpectedResults().addMetadata(key, value);
//token 3: EOL or ,
token = st.nextToken();
if (!endOfLineOrFile(token) && token != (int) ',')
{
throw new ParseException("Expected EOL or EOF or a comma on line " + st.lineno(), st.lineno());
}
}
}
return this.getParser().getBeginningOfLineState();
}
示例10: parseAttributes
import java.io.StreamTokenizer; //導入方法依賴的package包/類
private void parseAttributes(StreamTokenizer st) throws IOException, ParseException
{
int token = st.nextToken();
boolean wantAttribute = true;
while (token != StreamTokenizer.TT_EOL)
{
if (wantAttribute)
{
if (token != StreamTokenizer.TT_WORD && token != QUOTE_TOKEN)
{
throw new ParseException("expected an column name on line " + st.lineno(), st.lineno());
}
this.getParser().getExpectedTable().addColumnHeader(st.sval);
}
else
{
if (token != ',')
{
throw new ParseException("Expected a comma on line " + st.lineno(), st.lineno());
}
}
wantAttribute = !wantAttribute;
token = st.nextToken();
}
if (wantAttribute)
{
throw new ParseException("extra comma at the end of line " + st.lineno(), st.lineno());
}
}
示例11: parse
import java.io.StreamTokenizer; //導入方法依賴的package包/類
@Override
public ParserState parse(StreamTokenizer st) throws IOException, ParseException
{
int token = st.ttype;
if (token != StreamTokenizer.TT_WORD || !st.sval.equals(ExpectedResultsParser.SECTION_IDENTIFIER))
{
throw new ParseException("expected line " + st.lineno() + " to begin with Section", st.lineno());
}
token = st.nextToken();
if (token != StreamTokenizer.TT_WORD && token != '"')
{
throw new ParseException("expected a section name on line " + st.lineno(), st.lineno());
}
String testName = st.sval;
token = st.nextToken();
String tableName = null;
if (token == StreamTokenizer.TT_WORD || token == '"')
{
tableName = st.sval;
token = st.nextToken();
}
this.getParser().startNewSection(testName, tableName);
if (token != StreamTokenizer.TT_EOL)
{
throw new ParseException("invalid data after the class name on line " + st.lineno(), st.lineno());
}
return this.getParser().getHeaderState();
}
示例12: parse
import java.io.StreamTokenizer; //導入方法依賴的package包/類
@Override
public ParserState parse(StreamTokenizer st) throws IOException, ParseException
{
if (this.sectionName == null)
{
throw new ParseException("no section name found before line " + st.lineno(), st.lineno());
}
// parse the data
int currentAttribute = 0;
int token = st.ttype;
boolean wantData = true;
List<Object> rowValue = FastList.newList();
while (token != StreamTokenizer.TT_EOL && token != StreamTokenizer.TT_EOF)
{
if (wantData)
{
this.getParser().getExpectedTable().parseData(st, currentAttribute, rowValue);
currentAttribute++;
}
else
{
if (token != ',')
{
throw new ParseException("Expected a comma on line " + st.lineno(), st.lineno());
}
}
wantData = !wantData;
token = st.nextToken();
}
if (Iterate.notEmpty(rowValue))
{
this.getParser().getExpectedTable().addRowToList(rowValue);
}
return this.getParser().getBeginningOfLineState();
}
示例13: parseData
import java.io.StreamTokenizer; //導入方法依賴的package包/類
public void parseData(StreamTokenizer st, int currentNumber, List<Object> rowValue) throws ParseException
{
if (currentNumber >= this.headers.size())
{
throw new ParseException("extra data on line " + st.lineno(), st.lineno());
}
if (st.ttype == StreamTokenizer.TT_NUMBER)
{
rowValue.add(st.nval);
}
else
{
rowValue.add(st.sval);
}
}
示例14: parse
import java.io.StreamTokenizer; //導入方法依賴的package包/類
public ParserState parse(StreamTokenizer st) throws IOException, ParseException
{
int token = st.ttype;
if (token != StreamTokenizer.TT_WORD || !st.sval.equals(AbstractMithraDataFileParser.CLASS_IDENTIFIER))
{
throw new ParseException("expected line " + st.lineno() + " to begin with class", st.lineno());
}
token = st.nextToken();
if (token != StreamTokenizer.TT_WORD)
{
throw new ParseException("expected a class name on line "+st.lineno(), st.lineno());
}
this.getParser().addNewMithraParsedData();
String className = st.sval;
try
{
this.getParser().getCurrentParsedData().setParsedClassName(className);
}
catch (Exception e)
{
ParseException parseException = new ParseException("no such class (or finder): "+className+" on line "+st.lineno(), st.lineno());
parseException.initCause(e);
throw parseException;
}
this.getParser().getDataReaderState().setClass(className, st.lineno());
token = st.nextToken();
if (token != StreamTokenizer.TT_EOL)
{
throw new ParseException("invalid data after the class name on line "+st.lineno(), st.lineno());
}
return this.getParser().getAttributeReaderState();
}
示例15: parseData
import java.io.StreamTokenizer; //導入方法依賴的package包/類
public void parseData(StreamTokenizer st, int attributeNumber, Object currentData) throws ParseException
{
if (attributeNumber >= this.attributes.size())
{
throw new ParseException("extra data on line "+st.lineno(),st.lineno());
}
Attribute attribute = this.attributes.get(attributeNumber);
int token = st.ttype;
switch (token)
{
case StreamTokenizer.TT_NUMBER:
attribute.parseNumberAndSet(st.nval, currentData, st.lineno());
break;
case StreamTokenizer.TT_WORD:
String word = st.sval;
attribute.parseWordAndSet(word, currentData, st.lineno());
break;
case '"':
attribute.parseStringAndSet(st.sval, currentData, st.lineno(), simpleDateFormat);
break;
case StreamTokenizer.TT_EOL:
throw new RuntimeException("should never get here");
case StreamTokenizer.TT_EOF:
throw new ParseException("Unexpected end of file", st.lineno());
default:
char ch = (char)st.ttype;
throw new ParseException("unexpected character "+ch+" on line "+st.lineno()+" attribute count "+attributeNumber, st.lineno());
}
}