Пример #1
1
  /** This method is a hack. I really want another constructor. */
  public static Obj3d parseFile(InputStream is, ModelViewer modelViewer, boolean register)
      throws IOException, FileFormatException {

    StreamTokenizer st = new StreamTokenizer(new BufferedReader(new InputStreamReader(is)));
    st.eolIsSignificant(true);
    st.commentChar('#');

    Obj3d obj3d = new Obj3d(st, modelViewer, register);

    // should be at end of file
    is.close();
    if (st.ttype != StreamTokenizer.TT_EOF) {
      throw new FileFormatException(is.toString());
    }
    return obj3d;
  }
Пример #2
0
 int ct() throws IOException {
   FileReader fr = new FileReader("mf.dat");
   StreamTokenizer st = new StreamTokenizer(fr);
   st.eolIsSignificant(true);
   int tok = st.nextToken();
   int ctr = 0;
   while (tok != -1) {
     switch (tok) {
       case -3:
         {
           break;
         }
       case -2:
         {
           break;
         }
       case 10:
         {
           ctr++;
           break;
         }
     }
     tok = st.nextToken();
   }
   return ctr;
 }
Пример #3
0
  private void setupTokenizer() {
    st.resetSyntax();
    st.wordChars('a', 'z');
    st.wordChars('A', 'Z');
    st.wordChars('0', '9');
    st.wordChars(':', ':');
    st.wordChars('.', '.');
    st.wordChars('_', '_');
    st.wordChars('-', '-');
    st.wordChars('/', '/');
    st.wordChars('\\', '\\');
    st.wordChars('$', '$');
    st.wordChars('{', '{'); // need {} for property subst
    st.wordChars('}', '}');
    st.wordChars('*', '*');
    st.wordChars('+', '+');
    st.wordChars('~', '~');
    // XXX check ASCII table and add all other characters except special

    // special: #="(),
    st.whitespaceChars(0, ' ');
    st.commentChar('#');
    st.eolIsSignificant(true);
    st.quoteChar('\"');
  }
Пример #4
0
  /** Create an HTTP tokenizer, given a StreamTokenizer for the web page. */
  public HttpTokenizer(StreamTokenizer tokens) throws IOException {
    // Create a stream tokenizer
    this.tokens = tokens;

    // Set up the appropriate defaults
    tokens.eolIsSignificant(false);
    tokens.lowerCaseMode(true);
    tokens.wordChars('<', '<');
    tokens.wordChars('>', '>');
    tokens.wordChars('/', '/');
    tokens.wordChars('=', '=');
    tokens.wordChars('@', '@');
    tokens.wordChars('!', '!');
    tokens.wordChars('-', '-');
    tokens.ordinaryChar('.');
    tokens.ordinaryChar('?');
  }
Пример #5
0
  public CSVReader(BufferedReader input, char customizedSeparator) {
    this.separator = customizedSeparator;

    parser = new StreamTokenizer(input);
    parser.ordinaryChars(0, 255);
    parser.wordChars(0, 255);
    parser.ordinaryChar('\"');
    parser.ordinaryChar(customizedSeparator);

    // Need to do set EOL significance after setting ordinary and word
    // chars, and need to explicitly set \n and \r as whitespace chars
    // for EOL detection to work
    parser.eolIsSignificant(true);
    parser.whitespaceChars('\n', '\n');
    parser.whitespaceChars('\r', '\r');
    atEOF = false;
  }
Пример #6
0
  private static void readConfig(File confFile) {

    System.out.println("Reading configuration file: " + confFile);

    try {
      StreamTokenizer tokenizer = new StreamTokenizer(new BufferedReader(new FileReader(confFile)));
      tokenizer.eolIsSignificant(true);
      tokenizer.slashStarComments(true);

      boolean EOF = false;
      int tokType = 0;
      Vector words = new Vector();
      while (!EOF) {
        if ((tokType = tokenizer.nextToken()) == StreamTokenizer.TT_EOF) {
          EOF = true;
        } else if (tokType != StreamTokenizer.TT_EOL) {
          if (tokenizer.sval != null) {
            words.addElement(tokenizer.sval);
          }
        } else {
          if (words.size() == 2) {
            String key = (String) words.elementAt(0);
            String value = (String) words.elementAt(1);
            if (key.equals("SRSServer")) {
              srsServer = new String(value);
            } else if (key.equals("Database")) {
              database = new String(value);
            } else if (key.equals("Layout")) {
              layout = new String(value);
            } else if (key.equals("AutosaveInterval")) {
              if (value.equals("none")) {
                setAutosaveInterval(-1);
              } else {
                try {
                  setAutosaveInterval(Integer.parseInt(value));
                } catch (NumberFormatException e) {
                  System.err.println("Can't parse number: " + value);
                }
              }
            } else if (key.equals("ColourSchemeInstall")) {
              try {
                String installString = value;
                int breakIndex = installString.indexOf(":");

                if (breakIndex < 0) {
                  // adapterRegistry.installDataAdapter(installString);
                } else {
                  String driverName = installString.substring(0, breakIndex);
                  String driverDesc = installString.substring(breakIndex + 1);
                  // adapterRegistry.installDataAdapter(driverName);
                }
              } catch (Throwable e) {
                System.err.println("Could not install driver " + value + " because of " + e);
              }
            } else if (key.equals("FormatAdapterInstall")) {
              try {
                String installString = value;
                int breakIndex = installString.indexOf(":");

                if (breakIndex < 0) {
                  // adapterRegistry.installDataAdapter(installString);
                } else {
                  String driverName = installString.substring(0, breakIndex);
                  String driverDesc = installString.substring(breakIndex + 1);
                  // adapterRegistry.installDataAdapter(driverName);
                }
              } catch (Throwable e) {
                System.err.println("Could not install driver " + value + " because of " + e);
              }
            } else {
              System.out.println("Unknown config key " + key);
            }
          } else {
            if (words.size() != 0) {
              System.out.println(
                  "Too many words on line beginning "
                      + (String) words.elementAt(0)
                      + " in config file");
            }
          }

          words.removeAllElements();
        }
      }
      return;

    } catch (Exception ex) {
      System.out.println(ex);
      return;
    }
  }