1 package net.sf.pzfilereader.examples.delimiteddynamiccolumns;
2
3
4
5
6
7
8 import java.io.File;
9 import java.util.Iterator;
10
11 import net.sf.pzfilereader.DataError;
12 import net.sf.pzfilereader.DataSet;
13 import net.sf.pzfilereader.DefaultPZParserFactory;
14 import net.sf.pzfilereader.DataSet;
15 import net.sf.pzfilereader.PZParser;
16 import net.sf.pzfilereader.ordering.OrderBy;
17 import net.sf.pzfilereader.ordering.OrderColumn;
18
19 /**
20 * @author zepernick
21 *
22 * TODO To change the template for this generated type comment go to Window -
23 * Preferences - Java - Code Style - Code Templates
24 */
25 public class DelimitedWithPZMap {
26 public static void main(final String[] args) throws Exception {
27
28 String mapping = getDefaultMapping();
29 String data = getDefaultDataFile();
30 call(mapping, data);
31
32 }
33
34 public static String getDefaultDataFile() {
35 return "PEOPLE-CommaDelimitedWithQualifierAndHeaderTrailerRecError.txt";
36 }
37
38 public static String getDefaultMapping() {
39 return "PEOPLE-DelimitedWithHeaderTrailer.pzmap.xml";
40 }
41
42 public static void call(String mapping, String data) throws Exception {
43
44
45
46 OrderBy orderby = null;
47 final PZParser pzparser = DefaultPZParserFactory.getInstance().newDelimitedParser(new File(mapping),
48 new File(data), ',', '"', true);
49 final DataSet ds = pzparser.parse();
50
51
52 orderby = new OrderBy();
53 orderby.addOrderColumn(new OrderColumn("CITY", false));
54 orderby.addOrderColumn(new OrderColumn("LASTNAME", true));
55
56
57 String[] colNames = ds.getColumns();
58
59 while (ds.next()) {
60
61 if (ds.isRecordID("header")) {
62 System.out.println(">>>>found header");
63 System.out.println("COLUMN NAME: INDICATOR VALUE: " + ds.getString("RECORDINDICATOR"));
64 System.out.println("COLUMN NAME: HEADERDATA VALUE: " + ds.getString("HEADERDATA"));
65 System.out.println("===========================================================================");
66 continue;
67 }
68
69 if (ds.isRecordID("trailer")) {
70 System.out.println(">>>>found trailer");
71 System.out.println("COLUMN NAME: INDICATOR VALUE: " + ds.getString("RECORDINDICATOR"));
72 System.out.println("COLUMN NAME: TRAILERDATA VALUE: " + ds.getString("TRAILERDATA"));
73 System.out.println("===========================================================================");
74 continue;
75 }
76
77 for (int i = 0; i < colNames.length; i++) {
78 System.out.println("COLUMN NAME: " + colNames[i] + " VALUE: " + ds.getString(colNames[i]));
79 }
80
81 System.out.println("===========================================================================");
82 }
83
84 if (ds.getErrors() != null && ds.getErrors().size() > 0) {
85 System.out.println("<<<<FOUND ERRORS IN FILE>>>>");
86 final Iterator pzerrors = ds.getErrors().iterator();
87 while (pzerrors.hasNext()) {
88 final DataError error = (DataError)pzerrors.next();
89 System.out.println("Error Msg: " + error.getErrorDesc() + " line no: " + error.getLineNo());
90 }
91
92 }
93
94 }
95 }