/** LineFieldsParser.java - reads in each line from a file and splits it into fields By Rowland http://home.comcast.net/~rowland3/ **/ import java.io.*; import java.util.*; //------------------------------------------------------------------------------ public class LineFieldsParser { protected LineNumberReader in; protected int token; protected boolean gotToken; protected StringTokenizer st; public LineFieldsParser(String fileSpec) throws Exception { File file= new File(fileSpec); if (!file.exists()) throw new IOException("No such file: "+ fileSpec); Reader reader= new InputStreamReader(new FileInputStream(fileSpec)); in= new LineNumberReader(reader); run(); } public LineFieldsParser(InputStreamReader reader) throws Exception { in= new LineNumberReader(reader); run(); } protected void run() { String line; try { while ((line=in.readLine())!= null) doLine(line); in.close(); } catch (Exception E) { System.err.println("ERR LineFieldsParser run: "+ E.getMessage()); } } protected void doLine(String line) { StringTokenizer st= new StringTokenizer(line); Vector v= new Vector(); while (st.hasMoreTokens()) { String field= st.nextToken(); v.add(field); } st= null; Object[] fields= v.toArray(); v= null; try { callback(fields); } catch (Exception E) { System.err.println("ERR LineFieldsParser callback: "+ E.getMessage()); } } /** callback - override in derived class. Gets fed an array of fields for each line **/ protected void callback(Object[] fields) throws Exception { for (int i= 0; i