예제 #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
  /**
   * Configure the lexical analyzer.
   *
   * @param reader the input stream reader
   * @return an s-expression lexer
   */
  private StreamTokenizer createLexer(Reader reader) {
    StreamTokenizer tokenizer = new StreamTokenizer(reader);

    tokenizer.resetSyntax();
    tokenizer.eolIsSignificant(false);
    tokenizer.whitespaceChars(0, ' ');
    tokenizer.wordChars('!', '!');
    tokenizer.wordChars('*', 'z');

    return tokenizer;
  }
  // s is the effective dimension if > 0, otherwise it is dim
  private void readData(Reader re, int r1, int s1) throws IOException, NumberFormatException {
    try {
      StreamTokenizer st = new StreamTokenizer(re);
      if (st == null) return;
      st.eolIsSignificant(false);
      st.slashSlashComments(true);

      int i = st.nextToken();
      if (i != StreamTokenizer.TT_NUMBER) throw new NumberFormatException();
      b = (int) st.nval;
      st.nextToken();
      numCols = (int) st.nval;
      st.nextToken();
      numRows = (int) st.nval;
      st.nextToken();
      numPoints = (int) st.nval;
      st.nextToken();
      dim = (int) st.nval;
      if (dim < 1) {
        System.err.println(PrintfFormat.NEWLINE + "DigitalNetBase2FromFile:   dimension dim <= 0");
        throw new IllegalArgumentException("dimension dim <= 0");
      }
      if (r1 > numRows)
        throw new IllegalArgumentException(
            "DigitalNetBase2FromFile:   One must have   r1 <= Max num rows");
      if (s1 > dim) {
        throw new IllegalArgumentException("s1 is too large");
      }
      if (s1 > 0) dim = s1;
      if (r1 > 0) numRows = r1;

      if (b != 2) {
        System.err.println("***** DigitalNetBase2FromFile:    only base 2 allowed");
        throw new IllegalArgumentException("only base 2 allowed");
      }
      genMat = new int[dim * numCols];
      for (i = 0; i < dim; i++)
        for (int c = 0; c < numCols; c++) {
          st.nextToken();
          genMat[i * numCols + c] = (int) st.nval;
        }

    } catch (NumberFormatException e) {
      System.err.println("   DigitalNetBase2FromFile:   not a number  " + e);
      throw e;
    }
  }
예제 #6
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('?');
  }
예제 #7
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;
  }
예제 #8
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;
    }
  }
예제 #9
0
파일: DAVE.java 프로젝트: nasa/DAVEtools
  /**
   * Requests new model inputs from user.
   *
   * <p>Will return -1 if user signals end-of-input ( <code>^d</code>)
   *
   * @param inVec A {@link VectorInfoArrayList} listing inputs and default values
   * @return int -1 to quit, 0 to keep going
   * @throws IOException;
   */
  public int loadInputs(VectorInfoArrayList inVec) throws IOException {
    int tokenType;

    // The following mumbo-jumbo necessary to take stdin and parse it
    FileReader frin = new FileReader(FileDescriptor.in);
    StreamTokenizer st = new StreamTokenizer(frin);

    // Tell parser to look for double-precision numbers and EOLs
    // Note - can't use exponential notation; only 0-9, -, .
    st.parseNumbers();
    st.eolIsSignificant(true);

    // Write header
    System.out.println();
    System.out.println(" Specify input values:");

    // Loop for each input block that might need value
    Iterator<VectorInfo> in = inVec.iterator();
    while (in.hasNext()) {
      boolean blankLine = false;
      VectorInfo inVal = in.next();

      // write name, units, default value
      System.out.print(
          "   " + inVal.getName() + " (" + inVal.getUnits() + ") [" + inVal.getValue() + "]  : ");

      // look for number in input stream; abort on EOF; skip to next on EOL
      do { // look for number or EOL or EOF
        tokenType = st.nextToken();
        // System.out.println("tokenType was " + tokenType);
        if (tokenType == StreamTokenizer.TT_EOF) {
          return -1; // quit
        }
        if (tokenType == StreamTokenizer.TT_EOL) { // skip to next param
          blankLine = true;
          break;
        }
      } while (tokenType != StreamTokenizer.TT_NUMBER); // keep looking until number found

      if (!blankLine) {
        // if not empty line, interpret number and save in block
        //              System.out.println("Input value was " + st.nval);
        try {
          inVal.setValue(st.nval);
          //              System.out.println("setValue called for " + inVal.getName() + " with value
          // of " + st.nval);
        } catch (NumberFormatException e) {
          // take no action - leave value as is
        }

        // look for EOL so we can ignore it
        do {
          tokenType = st.nextToken();
          //              System.out.println("skipping tokenType " + tokenType );
          if (tokenType == StreamTokenizer.TT_EOF) {
            return -1;
          }
        } while (tokenType != StreamTokenizer.TT_EOL);
      }
    }
    return 0; // indicate keep going
  }