Package java.io

Examples of java.io.StreamTokenizer


public class WordWhiteChars implements Testlet
{
  public void test (TestHarness harness)
  {
    StreamTokenizer st = new StreamTokenizer(new StringReader("foo bar,baz"));
    // Everything is a word character.
    st.wordChars(0, 255);
    // Except for spaces and commas
    st.whitespaceChars(' ', ' ');
    st.whitespaceChars(',', ',');

    try
      {
  harness.check(st.nextToken(), StreamTokenizer.TT_WORD);
  harness.check(st.sval, "foo");
  harness.check(st.nextToken(), StreamTokenizer.TT_WORD);
  harness.check(st.sval, "bar");
  harness.check(st.nextToken(), StreamTokenizer.TT_WORD);
  harness.check(st.sval, "baz");
  harness.check(st.nextToken(), StreamTokenizer.TT_EOF);
      }
    catch (IOException ioe)
      {
  harness.fail(ioe.toString());
      }
View Full Code Here


    return new ElementMatcher(tokenizer.sval);
  }

  public static NodeMatcher parse(final String s) throws IOException
  {
    final StreamTokenizer tokenizer = new StreamTokenizer(new StringReader(s));
    tokenizer.wordChars('0', '9');
    tokenizer.ordinaryChar('.');
    tokenizer.ordinaryChar(',');
    tokenizer.ordinaryChars(0, ' ');

    ElementMatcher elementMatcher = null;
    NodeMatcher n = null;
    Type selectorType = Type.Start;
    int token;
    while ((token = tokenizer.nextToken()) != StreamTokenizer.TT_EOF)
    {
      if (token == StreamTokenizer.TT_WORD || token == '*')
      {
        NodeMatcher matcher = null;

View Full Code Here

    * the last row is followed by a blank line.
   @param input the input stream.
    */
   public static JamMatrix read(BufferedReader input) throws java.io.IOException
   {
      StreamTokenizer tokenizer = new StreamTokenizer(input);

      // Although StreamTokenizer will parse numbers, it doesn't recognize
      // scientific notation (E or D); however, Double.valueOf does.
      // The strategy here is to disable StreamTokenizer's number parsing.
      // We'll only get whitespace delimited words, EOL's and EOF's.
      // These words should all be numbers, for Double.valueOf to parse.

      tokenizer.resetSyntax();
      tokenizer.wordChars(0, 255);
      tokenizer.whitespaceChars(0, ' ');
      tokenizer.eolIsSignificant(true);
      // TODO: replace by eg:
     
      java.util.Vector<Double> vD = new java.util.Vector<Double>();

      // Ignore initial empty lines
      while (tokenizer.nextToken() == StreamTokenizer.TT_EOL);
      if (tokenizer.ttype == StreamTokenizer.TT_EOF)
         throw new java.io.IOException("Unexpected EOF on matrix read.");
      do
      {
         vD.addElement(Double.valueOf(tokenizer.sval)); // Read & store 1st row.
      }
      while (tokenizer.nextToken() == StreamTokenizer.TT_WORD);

      int n = vD.size()// Now we've got the number of columns!
      double row[] = new double[n];
      for (int j = 0; j < n; j++// extract the elements of the 1st row.
         row[j] = vD.elementAt(j).doubleValue();
     
      // TODO: replace obsolete Vector by ArrayList
      java.util.Vector<double[]> v = new java.util.Vector<double[]>();
     
     
      v.addElement(row)// Start storing rows instead of columns.
      while (tokenizer.nextToken() == StreamTokenizer.TT_WORD)
      {
         // While non-empty lines
         v.addElement(row = new double[n]);
         int j = 0;
         do
         {
            if (j >= n)
               throw new java.io.IOException("Row " + v.size() + " is too long.");
            row[j++] = Double.valueOf(tokenizer.sval).doubleValue();
         }
         while (tokenizer.nextToken() == StreamTokenizer.TT_WORD);
         if (j < n)
            throw new java.io.IOException("Row " + v.size() + " is too short.");
      }
      int m = v.size()// Now we've got the number of rows.
      double[][] A = new double[m][];
View Full Code Here

  private void GetEntries(File tex) {
    BufferedReader reader;
    try {
      reader = new BufferedReader(new FileReader(tex));
      StreamTokenizer toki = new StreamTokenizer(reader);
      toki.resetSyntax();
      toki.eolIsSignificant(false);
      toki.commentChar('%');
      toki.wordChars('a', 'z');
      toki.wordChars('A', 'Z');
      toki.wordChars('0', '9');
      toki.wordChars('-', '-');
      toki.wordChars(' ', ' ');
      toki.wordChars(',', ',');

      int type;
      boolean cite = false;
      while ((type = toki.nextToken()) != StreamTokenizer.TT_EOF) {
        if (type == StreamTokenizer.TT_WORD) {

          String val = toki.sval;

          if (cite) {
View Full Code Here

     * the last row is followed by a blank line.
   @param input the input stream.
   */

   public static Matrix read (BufferedReader input) throws java.io.IOException {
      StreamTokenizer tokenizer= new StreamTokenizer(input);

      // Although StreamTokenizer will parse numbers, it doesn't recognize
      // scientific notation (E or D); however, Double.valueOf does.
      // The strategy here is to disable StreamTokenizer's number parsing.
      // We'll only get whitespace delimited words, EOL's and EOF's.
      // These words should all be numbers, for Double.valueOf to parse.

      tokenizer.resetSyntax();
      tokenizer.wordChars(0,255);
      tokenizer.whitespaceChars(0, ' ');
      tokenizer.eolIsSignificant(true);
      java.util.Vector v = new java.util.Vector();

      // Ignore initial empty lines
      while (tokenizer.nextToken() == StreamTokenizer.TT_EOL);
      if (tokenizer.ttype == StreamTokenizer.TT_EOF)
  throw new java.io.IOException("Unexpected EOF on matrix read.");
      do {
         v.addElement(Double.valueOf(tokenizer.sval)); // Read & store 1st row.
      } while (tokenizer.nextToken() == StreamTokenizer.TT_WORD);

      int n = v.size()// Now we've got the number of columns!
      double row[] = new double[n];
      for (int j=0; j<n; j++// extract the elements of the 1st row.
         row[j]=((Double)v.elementAt(j)).doubleValue();
      v.removeAllElements();
      v.addElement(row)// Start storing rows instead of columns.
      while (tokenizer.nextToken() == StreamTokenizer.TT_WORD) {
         // While non-empty lines
         v.addElement(row = new double[n]);
         int j = 0;
         do {
            if (j >= n) throw new java.io.IOException
               ("Row " + v.size() + " is too long.");
            row[j++] = Double.valueOf(tokenizer.sval).doubleValue();
         } while (tokenizer.nextToken() == StreamTokenizer.TT_WORD);
         if (j < n) throw new java.io.IOException
            ("Row " + v.size() + " is too short.");
      }
      int m = v.size()// Now we've got the number of rows.
      double[][] A = new double[m][];
View Full Code Here

        if (!coloursFile.exists()) {
            return;
        }

        Reader cr = new FileReader(coloursFile);
        StreamTokenizer st = new StreamTokenizer(cr);

        st.lowerCaseMode(true);
        st.quoteChar('"');
        st.commentChar('#');

        scan: while (true) {
            red = 0;
            green = 0;
            blue = 0;

            switch (st.nextToken()) {
            case StreamTokenizer.TT_EOF:
                break scan;
            case StreamTokenizer.TT_EOL:
                break scan;
            case StreamTokenizer.TT_WORD:
                // read in
                String key = st.sval;
                if (key.equals("unitsize")) { //$NON-NLS-1$
                    st.nextToken();
                } else if (key.equals("background")) { //$NON-NLS-1$
                    st.nextToken();
                    red = (int) st.nval;
                    st.nextToken();
                    green = (int) st.nval;
                    st.nextToken();
                    blue = (int) st.nval;

                    BACKGROUND = new Color(red, green, blue);
                } else if (key.equals("heavywoods")) { //$NON-NLS-1$
                    st.nextToken();
                    red = (int) st.nval;
                    st.nextToken();
                    green = (int) st.nval;
                    st.nextToken();
                    blue = (int) st.nval;

                    HEAVY_WOODS = new Color(red, green, blue);
                } else if (key.equals("ultraheavywoods")) { //$NON-NLS-1$
                    st.nextToken();
                    red = (int) st.nval;
                    st.nextToken();
                    green = (int) st.nval;
                    st.nextToken();
                    blue = (int) st.nval;

                    ULTRA_HEAVY_WOODS = new Color(red, green, blue);
                } else if (key.equals("sinkhole")) { //$NON-NLS-1$
                    st.nextToken();
                    red = (int) st.nval;
                    st.nextToken();
                    green = (int) st.nval;
                    st.nextToken();
                    blue = (int) st.nval;

                    SINKHOLE = new Color(red, green, blue);
                } else if (key.equals("smokeandfire")) { //$NON-NLS-1$
                    st.nextToken();
                    red = (int) st.nval;
                    st.nextToken();
                    green = (int) st.nval;
                    st.nextToken();
                    blue = (int) st.nval;

                    SMOKE_AND_FIRE = new Color(red, green, blue);
                } else {
                    st.nextToken();
                    red = (int) st.nval;
                    st.nextToken();
                    green = (int) st.nval;
                    st.nextToken();
                    blue = (int) st.nval;

                    m_terrainColors[Terrains.getType(key)] = new Color(red,
                            green, blue);
                }
View Full Code Here

        if (!coloursFile.exists()) {
            return;
        }

        Reader cr = new FileReader(coloursFile);
        StreamTokenizer st = new StreamTokenizer(cr);

        st.lowerCaseMode(true);
        st.quoteChar('"');
        st.commentChar('#');

        scan: while (true) {
            red = 0;
            green = 0;
            blue = 0;

            switch (st.nextToken()) {
                case StreamTokenizer.TT_EOF:
                    break scan;
                case StreamTokenizer.TT_EOL:
                    break scan;
                case StreamTokenizer.TT_WORD:
                    // read in
                    String key = st.sval;
                    if (key.equals("unitsize")) { //$NON-NLS-1$
                        st.nextToken();
                    } else if (key.equals("background")) { //$NON-NLS-1$
                        st.nextToken();
                        red = (int) st.nval;
                        st.nextToken();
                        green = (int) st.nval;
                        st.nextToken();
                        blue = (int) st.nval;

                        BACKGROUND = new Color(red, green, blue);
                    } else if (key.equals("heavywoods")) { //$NON-NLS-1$
                        st.nextToken();
                        red = (int) st.nval;
                        st.nextToken();
                        green = (int) st.nval;
                        st.nextToken();
                        blue = (int) st.nval;

                        HEAVY_WOODS = new Color(red, green, blue);
                    } else if (key.equals("ultraheavywoods")) { //$NON-NLS-1$
                        st.nextToken();
                        red = (int) st.nval;
                        st.nextToken();
                        green = (int) st.nval;
                        st.nextToken();
                        blue = (int) st.nval;

                        ULTRA_HEAVY_WOODS = new Color(red, green, blue);
                    } else if (key.equals("sinkhole")) { //$NON-NLS-1$
                        st.nextToken();
                        red = (int) st.nval;
                        st.nextToken();
                        green = (int) st.nval;
                        st.nextToken();
                        blue = (int) st.nval;

                        SINKHOLE = new Color(red, green, blue);
                    } else if (key.equals("smokeandfire")) { //$NON-NLS-1$
                        st.nextToken();
                        red = (int) st.nval;
                        st.nextToken();
                        green = (int) st.nval;
                        st.nextToken();
                        blue = (int) st.nval;

                        SMOKE_AND_FIRE = new Color(red, green, blue);
                    } else {
                        st.nextToken();
                        red = (int) st.nval;
                        st.nextToken();
                        green = (int) st.nval;
                        st.nextToken();
                        blue = (int) st.nval;

                        m_terrainColors[Terrains.getType(key)] = new Color(red,
                                green, blue);
                    }
View Full Code Here

    public void loadFromFile(String filename) throws IOException {
        // make inpustream for board
        Reader r = new BufferedReader(new FileReader(
                "data/images/hexes/" + filename)); //$NON-NLS-1$
        // read board, looking for "size"
        StreamTokenizer st = new StreamTokenizer(r);
        st.eolIsSignificant(true);
        st.commentChar('#');
        st.quoteChar('"');
        st.wordChars('_', '_');
        while (st.nextToken() != StreamTokenizer.TT_EOF) {
            int elevation = 0;
            String terrain = null;
            String theme = null;
            String imageName = null;
            if (st.ttype == StreamTokenizer.TT_WORD
                    && (st.sval.equals("base") || st.sval.equals("super"))) { //$NON-NLS-1$ //$NON-NLS-2$
                boolean base = st.sval.equals("base"); //$NON-NLS-1$

                if (st.nextToken() == StreamTokenizer.TT_NUMBER) {
                    elevation = (int) st.nval;
                } else {
                    elevation = ITerrain.WILDCARD;
                }
                st.nextToken();
                terrain = st.sval;
                st.nextToken();
                theme = st.sval;
                st.nextToken();
                imageName = st.sval;
                // add to list
                if (base) {
                    bases.add(new HexEntry(new Hex(elevation, terrain, theme),
                            imageName));
View Full Code Here

    public void loadFromFile(String filename) throws IOException {
        // make inpustream for board
        Reader r = new BufferedReader(new FileReader(
                "data/images/hexes/" + filename)); //$NON-NLS-1$
        // read board, looking for "size"
        StreamTokenizer st = new StreamTokenizer(r);
        st.eolIsSignificant(true);
        st.commentChar('#');
        st.quoteChar('"');
        st.wordChars('_', '_');
        while (st.nextToken() != StreamTokenizer.TT_EOF) {
            int elevation = 0;
            String terrain = null;
            String theme = null;
            String imageName = null;
            if (st.ttype == StreamTokenizer.TT_WORD
                    && (st.sval.equals("base") || st.sval.equals("super"))) { //$NON-NLS-1$ //$NON-NLS-2$
                boolean base = st.sval.equals("base"); //$NON-NLS-1$

                if (st.nextToken() == StreamTokenizer.TT_NUMBER) {
                    elevation = (int) st.nval;
                } else {
                    elevation = ITerrain.WILDCARD;
                }
                st.nextToken();
                terrain = st.sval;
                st.nextToken();
                theme = st.sval;
                st.nextToken();
                imageName = st.sval;
                // add to list
                if (base) {
                    bases.add(new HexEntry(new Hex(elevation, terrain, theme),
                            imageName));
View Full Code Here

    }

    public boolean parse(String locstring) {
        clear();
        StringReader s = new StringReader(locstring);
        st = new StreamTokenizer(s);
        return parse();
    }
View Full Code Here

TOP

Related Classes of java.io.StreamTokenizer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.