View Javadoc

1   package net.sf.pzfilereader.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.pzfilereader.DataSet;
12  import net.sf.pzfilereader.DefaultPZParserFactory;
13  import net.sf.pzfilereader.DataSet;
14  import net.sf.pzfilereader.PZParser;
15  
16  /**
17   * @author zepernick
18   * 
19   * TODO To change the template for this generated type comment go to Window -
20   * Preferences - Java - Code Style - Code Templates
21   */
22  public class NumericsAndDates {
23      public static void main(final String[] args) throws Exception {
24          String mapping = getDefaultMapping();
25          String data = getDefaultDataFile();
26          call(mapping, data);
27      }
28  
29      public static String getDefaultDataFile() {
30          return "INVENTORY-CommaDelimitedWithQualifier.txt";
31      }
32  
33      public static String getDefaultMapping() {
34          return "INVENTORY-Delimited.pzmap.xml";
35      }
36  
37      public static void call(String mapping, String data) throws Exception {
38          // wll provide a clean format for printing the date to the screen
39          final SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
40  
41          // delimited by a comma
42          // text qualified by double quotes
43          // ignore first record
44          final PZParser pzparser = DefaultPZParserFactory.getInstance().newDelimitedParser(new File(mapping), 
45                  new File(data), ',', '\"', true);
46          final DataSet ds = pzparser.parse();
47          // demonstrates the casting abilities of PZFileReader
48          while (ds.next()) {
49              System.out.println("Item Desc: " + ds.getString("ITEM_DESC") + " (String)");
50              System.out.println("In Stock: " + ds.getInt("IN_STOCK") + " (int)");
51              System.out.println("Price: " + ds.getDouble("PRICE") + " (double)");
52              System.out.println("Received Dt: " + sdf.format(ds.getDate("LAST_RECV_DT")) + " (Date)");
53              System.out.println("===========================================================================");
54          }
55      }
56  }