1 package net.sf.pzfilereader.examples.largedataset.delimiteddynamiccolumns;
2
3
4
5
6
7
8 import java.io.File;
9 import java.io.FileInputStream;
10
11 import net.sf.pzfilereader.DataSet;
12 import net.sf.pzfilereader.brparse.BuffReaderDelimPZParser;
13 import net.sf.pzfilereader.brparse.BuffReaderPZParseFactory;
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 LargeDelimitedWithPZMap {
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
29 public static String getDefaultDataFile() {
30 return "PEOPLE-CommaDelimitedWithQualifier.txt";
31 }
32
33 public static String getDefaultMapping() {
34 return "PEOPLE-Delimited.pzmap.xml";
35 }
36
37 public static void call(String mapping, String data) throws Exception {
38 String[] colNames = null;
39 FileInputStream pzmap = null;
40 FileInputStream fileToParse = null;
41 BuffReaderDelimPZParser pzparse = null;
42 try {
43 pzmap = new FileInputStream(new File(mapping));
44 fileToParse = new FileInputStream(new File(data));
45
46
47
48
49 pzparse = (BuffReaderDelimPZParser)BuffReaderPZParseFactory.getInstance().newDelimitedParser(pzmap,
50 fileToParse, ',', '"', true);
51
52 final DataSet ds = pzparse.parse();
53
54 colNames = ds.getColumns();
55
56 while (ds.next()) {
57 for (int i = 0; i < colNames.length; i++) {
58 System.out.println("COLUMN NAME: " + colNames[i] + " VALUE: " + ds.getString(colNames[i]));
59 }
60
61 System.out.println("===========================================================================");
62 }
63
64 if (ds.getErrors() != null && ds.getErrors().size() > 0) {
65 System.out.println("FOUND ERRORS IN FILE");
66 }
67
68 } finally {
69
70 pzparse.close();
71
72 }
73
74 }
75 }