View Javadoc

1   package net.sf.pzfilereader.examples.largedataset.fixedlengthdynamiccolumns;
2   
3   /*
4    * Created on Dec 31, 2004
5    *
6    */
7   
8   import java.io.File;
9   
10  import net.sf.pzfilereader.DataSet;
11  import net.sf.pzfilereader.brparse.BuffReaderFixedPZParser;
12  import net.sf.pzfilereader.brparse.BuffReaderPZParseFactory;
13  
14  
15  /**
16   * @author zepernick
17   * 
18   * TODO To change the template for this generated type comment go to Window -
19   * Preferences - Java - Code Style - Code Templates
20   */
21  public class LargeFixedLengthWithPZMap {
22      public static void main(final String[] args) throws Exception {
23          String mapping = getDefaultMapping();
24          String data = getDefaultDataFile();
25          call(mapping, data);
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(String mapping, String data) throws Exception {
37          String[] colNames = null;
38          BuffReaderFixedPZParser pzparse = null;
39          try {
40              pzparse = (BuffReaderFixedPZParser)BuffReaderPZParseFactory.getInstance().newFixedLengthParser(new File(mapping), 
41                      new File(data));
42      
43              final DataSet ds = pzparse.parse();
44              colNames = ds.getColumns();
45      
46              while (ds.next()) {
47                  for (int i = 0; i < colNames.length; i++) {
48                      System.out.println("COLUMN NAME: " + colNames[i] + " VALUE: " + ds.getString(colNames[i]));
49                  }
50      
51                  System.out.println("===========================================================================");
52              }
53              
54          } finally {
55              pzparse.close();
56          }
57  
58      }
59  }