package OT; import java.io.*; import java.net.*; import java.util.*; /** * Parse data file into vectors of data. * @version 1999-01-03 * @author Andrea Heiberg, University of Arizona */ public class DataFile { URL url; public DataFile(URL url) { this.url = url; } //end constructor public Vector createVectors() { InputStream is = null; StreamTokenizer st; Vector lines = new Vector(); Vector rawline = new Vector(); Double temp; try { is = url.openStream(); BufferedInputStream b = new BufferedInputStream(is, 4000); st = new StreamTokenizer(b); st.wordChars('+', '+'); st.wordChars('-', '-'); st.wordChars('*', '*'); st.commentChar('%'); st.quoteChar('"'); st.eolIsSignificant(true); try { while( st.ttype != StreamTokenizer.TT_EOF ) { switch ( st.nextToken() ) { case StreamTokenizer.TT_EOF: break; case StreamTokenizer.TT_WORD: //found a word; read in one raw line rawline.addElement(new String(st.sval)); while( st.ttype != StreamTokenizer.TT_EOF && st.ttype != StreamTokenizer.TT_EOL ) { switch ( st.nextToken() ) { case StreamTokenizer.TT_EOF: break; case StreamTokenizer.TT_EOL: break; case StreamTokenizer.TT_WORD: rawline.addElement(new String(st.sval)); break; case StreamTokenizer.TT_NUMBER: if (st.nval != 0) { Double d = new Double(st.nval); //convert number to string String t = new String(d.toString()); String s = new String(); if (t.length()>=3) { //java 1.1 s = t.substring(0,t.length()-2); } else { //java 1.0 s = t; } //end if rawline.addElement(s); } //end if break; case '"': rawline.addElement(new String(st.sval)); default: //ignore everything else break; } // end switch } //end while lines.addElement(rawline.clone()); //add this rawline to the vector of lines rawline.removeAllElements(); break; default: //ignore everything else break; } // end switch } // end while is.close(); return lines; } catch( Exception e) { System.out.println("DataFile: " + e); return null; } //end try } catch (Exception e) { System.out.println("DataFile: " + e); return null; } //end try } //end createVectors } //end class