View Javadoc

1   package net.sf.flatpack.examples.numericsanddates;
2   
3   /*
4    * Created on Dec 31, 2004
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          // wll provide a clean format for printing the date to the screen
38          final SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
39  
40          // delimited by a comma
41          // text qualified by double quotes
42          // ignore first record
43          final Parser pzparser = DefaultParserFactory.getInstance().newDelimitedParser(new File(mapping), new File(data), ',', '\"', true);
44          final DataSet ds = pzparser.parse();
45          // demonstrates the casting abilities of FlatPack
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  }