Java Code Examples for java.io.StreamTokenizer#lineno()

The following examples show how to use java.io.StreamTokenizer#lineno() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Harness.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
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());
    }
}
 
Example 2
Source File: Harness.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
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());
    }
}
 
Example 3
Source File: Harness.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
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());
        }
    }
}
 
Example 4
Source File: Harness.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
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());
    }
}
 
Example 5
Source File: GeoWKTParser.java    From crate with Apache License 2.0 6 votes vote down vote up
/** 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());
    }
}
 
Example 6
Source File: Harness.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
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());
    }
}
 
Example 7
Source File: Harness.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
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());
    }
}
 
Example 8
Source File: Harness.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
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());
        }
    }
}
 
Example 9
Source File: GeoWKTParser.java    From crate with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example 10
Source File: Harness.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
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());
        }
    }
}
 
Example 11
Source File: Harness.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
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());
    }
}
 
Example 12
Source File: AttributeReaderState.java    From reladomo with Apache License 2.0 5 votes vote down vote up
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());
    }
}
 
Example 13
Source File: DataReaderState.java    From reladomo with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 14
Source File: SimpleWKTShapeParser.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/** 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);
  }
}
 
Example 15
Source File: SimpleWKTShapeParser.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/** 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());
}
 
Example 16
Source File: SimpleWKTShapeParser.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/** 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());
}
 
Example 17
Source File: SectionReaderState.java    From tablasco with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 18
Source File: SimpleWKTShapeParser.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/** 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());
  }
}
 
Example 19
Source File: SimpleWKTShapeParser.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/** 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());
}
 
Example 20
Source File: ServiceConfigGuide.java    From emissary with Apache License 2.0 4 votes vote down vote up
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();
}