下面列出了java.io.StreamTokenizer#lineno ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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());
}
}
}
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());
}
}
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());
}
}
}
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());
}
}
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());
}
}
private static List<Coordinate> parseCoordinateList(StreamTokenizer stream, final boolean ignoreZValue)
throws IOException, ElasticsearchParseException {
CoordinatesBuilder coordinates = new CoordinatesBuilder();
boolean isOpenParen = false;
if (isNumberNext(stream) || (isOpenParen = nextWord(stream).equals(LPAREN))) {
coordinates.coordinate(parseCoordinate(stream, ignoreZValue));
}
if (isOpenParen && nextCloser(stream).equals(RPAREN) == false) {
throw new ElasticsearchParseException("expected: [{}]" + RPAREN + " but found: [{}]" + tokenString(stream), stream.lineno());
}
while (nextCloserOrComma(stream).equals(COMMA)) {
isOpenParen = false;
if (isNumberNext(stream) || (isOpenParen = nextWord(stream).equals(LPAREN))) {
coordinates.coordinate(parseCoordinate(stream, ignoreZValue));
}
if (isOpenParen && nextCloser(stream).equals(RPAREN) == false) {
throw new ElasticsearchParseException("expected: " + RPAREN + " but found: " + tokenString(stream), stream.lineno());
}
}
return coordinates.build();
}
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());
}
}
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());
}
}
}
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());
}
}
/** next word in the stream */
private static String nextWord(StreamTokenizer stream) throws ElasticsearchParseException, IOException {
switch (stream.nextToken()) {
case StreamTokenizer.TT_WORD:
final String word = stream.sval;
return word.equalsIgnoreCase(EMPTY) ? EMPTY : word;
case '(':
return LPAREN;
case ')':
return RPAREN;
case ',':
return COMMA;
default:
throw new ElasticsearchParseException("expected word but found: " + tokenString(stream), stream.lineno());
}
}
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());
}
}
/** next number in the stream */
private static double nextNumber(StreamTokenizer stream) throws IOException, ParseException {
if (stream.nextToken() == StreamTokenizer.TT_WORD) {
if (stream.sval.equalsIgnoreCase(NAN)) {
return Double.NaN;
} else {
try {
return Double.parseDouble(stream.sval);
} catch (NumberFormatException e) {
throw new ParseException("invalid number found: " + stream.sval, stream.lineno());
}
}
}
throw new ParseException("expected number but found: " + tokenString(stream), stream.lineno());
}
/** next word in the stream */
private static void checkEOF(StreamTokenizer stream) throws ParseException, IOException {
if (stream.nextToken() != StreamTokenizer.TT_EOF) {
throw new ParseException("expected end of WKT string but found additional text: "
+ tokenString(stream), stream.lineno());
}
}
@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();
}
/** expects either a closing LPAREN or comma as the next token */
private static String nextCloserOrComma(StreamTokenizer stream) throws IOException, ParseException {
String token = nextWord(stream);
if (token.equals(COMMA) || token.equals(RPAREN)) {
return token;
}
throw new ParseException("expected " + COMMA + " or " + RPAREN
+ " but found: " + tokenString(stream), stream.lineno());
}
/** next word in the stream */
private static String nextWord(StreamTokenizer stream) throws ParseException, IOException {
switch (stream.nextToken()) {
case StreamTokenizer.TT_WORD:
final String word = stream.sval;
return word.equalsIgnoreCase(EMPTY) ? EMPTY : word;
case '(': return LPAREN;
case ')': return RPAREN;
case ',': return COMMA;
}
throw new ParseException("expected word but found: " + tokenString(stream), stream.lineno());
}
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)
{
throw new ParseException("expected an attribute name on line "+st.lineno(), st.lineno());
}
this.getParser().getCurrentParsedData().addAttribute(st.sval, st.lineno());
}
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());
}
}
/** parse geometry from the stream tokenizer */
private static Object parseGeometry(StreamTokenizer stream, ShapeType shapeType) throws IOException, ParseException {
final ShapeType type = ShapeType.forName(nextWord(stream));
if (shapeType != null && shapeType != ShapeType.GEOMETRYCOLLECTION) {
if (type.wktName().equals(shapeType.wktName()) == false) {
throw new ParseException("Expected geometry type: [" + shapeType + "], but found: [" + type + "]", stream.lineno());
}
}
switch (type) {
case POINT:
return parsePoint(stream);
case MULTIPOINT:
return parseMultiPoint(stream);
case LINESTRING:
return parseLine(stream);
case MULTILINESTRING:
return parseMultiLine(stream);
case POLYGON:
return parsePolygon(stream);
case MULTIPOLYGON:
return parseMultiPolygon(stream);
case ENVELOPE:
return parseBBox(stream);
case GEOMETRYCOLLECTION:
return parseGeometryCollection(stream);
default:
throw new IllegalArgumentException("Unknown geometry type: " + type);
}
}
public ParserState parse(StreamTokenizer st) throws IOException, ParseException
{
if (dataClass == null)
{
throw new ParseException("no class name found before line "+st.lineno(), st.lineno());
}
MithraDataObject currentData;
currentData = this.getParser().getCurrentParsedData().createAndAddDataObject(st.lineno());
// parse the data
int currentAttribute = 0;
int token = st.ttype;
boolean wantData = true;
while(token != StreamTokenizer.TT_EOL && token != StreamTokenizer.TT_EOF)
{
if (wantData)
{
this.getParser().getCurrentParsedData().parseData(st, currentAttribute, currentData);
currentAttribute++;
}
else
{
if (token != ',')
{
throw new ParseException("Expected a comma on line "+st.lineno(), st.lineno());
}
}
wantData = !wantData;
token = st.nextToken();
}
return this.getParser().getBeginningOfLineState();
}
protected void readConfigData(final InputStream is, final String filename) throws IOException, ConfigSyntaxException {
final Reader r = new BufferedReader(new InputStreamReader(is));
final StreamTokenizer in = new StreamTokenizer(r);
int nextToken = StreamTokenizer.TT_WORD;
String parmName;
String sval;
int nval;
@SuppressWarnings("unused")
boolean paramTypeIsNumber;
in.commentChar('#');
in.wordChars(33, 33);
in.wordChars(36, 47);
in.wordChars(58, 64);
in.wordChars(91, 96);
in.wordChars(123, 65536);
parsing: while (nextToken != StreamTokenizer.TT_EOF) {
sval = "";
parmName = "";
nval = -1;
paramTypeIsNumber = false;
// Read three tokens at a time (X = Y)
nextToken = in.nextToken();
// Make sure the first token in the tuple is a word
if (nextToken == StreamTokenizer.TT_EOF) {
break parsing;
}
if (nextToken == StreamTokenizer.TT_NUMBER) {
throw new ConfigSyntaxException("Illegal token " + in.sval + ", missing quote on line " + in.lineno() + "?");
}
parmName = in.sval;
nextToken = in.nextToken();
// logger.debug("operator = [" + in.sval + "]");
this.operator = in.sval;
nextToken = in.nextToken();
if (nextToken == StreamTokenizer.TT_NUMBER) {
paramTypeIsNumber = true;
nval = (int) in.nval;
sval = Integer.valueOf(nval).toString();
} else {
sval = in.sval;
}
if (sval == null) {
// Problem is likely on previous line
throw new ConfigSyntaxException("Illegal token " + parmName + ", missing space or value on line " + (in.lineno() - 1) + "?");
}
handleNewEntry(parmName, sval, this.operator, filename, in.lineno() - 1, false);
}
r.close();
is.close();
}