1 package net.sf.flatpack.examples.numericsanddates;
2
3
4
5
6
7
8 import java.io.File;
9 import java.text.SimpleDateFormat;
10
11 import net.sf.flatpack.DataSet;
12 import net.sf.flatpack.DefaultParserFactory;
13 import net.sf.flatpack.Parser;
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 NumericsAndDates {
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 public static String getDefaultDataFile() {
29 return "INVENTORY-CommaDelimitedWithQualifier.txt";
30 }
31
32 public static String getDefaultMapping() {
33 return "INVENTORY-Delimited.pzmap.xml";
34 }
35
36 public static void call(final String mapping, final String data) throws Exception {
37
38 final SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
39
40
41
42
43 final Parser pzparser = DefaultParserFactory.getInstance().newDelimitedParser(new File(mapping), new File(data), ',', '\"', true);
44 final DataSet ds = pzparser.parse();
45
46 while (ds.next()) {
47 System.out.println("Item Desc: " + ds.getString("ITEM_DESC") + " (String)");
48 System.out.println("In Stock: " + ds.getInt("IN_STOCK") + " (int)");
49 System.out.println("Price: " + ds.getDouble("PRICE") + " (double)");
50 System.out.println("Received Dt: " + sdf.format(ds.getDate("LAST_RECV_DT")) + " (Date)");
51 System.out.println("===========================================================================");
52 }
53 }
54 }