View Javadoc

1   package net.sf.flatpack.examples.fixedlengthdynamiccolumns;
2   
3   /*
4    * Created on Dec 31, 2004
5    *
6    */
7   
8   import java.io.File;
9   
10  import net.sf.flatpack.DataSet;
11  import net.sf.flatpack.DefaultParserFactory;
12  import net.sf.flatpack.Parser;
13  
14  /**
15   * @author zepernick
16   * 
17   * TODO To change the template for this generated type comment go to Window -
18   * Preferences - Java - Code Style - Code Templates
19   */
20  public class FixedLengthWithPZMap {
21      public static void main(final String[] args) throws Exception {
22          final String mapping = getDefaultMapping();
23          final String data = getDefaultDataFile();
24          call(mapping, data);
25  
26      }
27  
28      public static String getDefaultDataFile() {
29          return "PEOPLE-FixedLength.txt";
30      }
31  
32      public static String getDefaultMapping() {
33          return "PEOPLE-FixedLength.pzmap.xml";
34      }
35  
36      public static void call(final String mapping, final String data) throws Exception {
37          final Parser pzparser = DefaultParserFactory.getInstance().newFixedLengthParser(new File(mapping), new File(data));
38          final DataSet ds = pzparser.parse();
39  
40          final String[] colNames = ds.getColumns();
41  
42          while (ds.next()) {
43              for (int i = 0; i < colNames.length; i++) {
44                  System.out.println("COLUMN NAME: " + colNames[i] + " VALUE: " + ds.getString(colNames[i]));
45              }
46  
47              System.out.println("===========================================================================");
48          }
49  
50      }
51  }