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