View Javadoc

1   package net.sf.flatpack.examples.multilinedelimitedrecord;
2   
3   /*
4    * Created on Dec 31, 2004
5    *
6    */
7   
8   import java.io.File;
9   
10  import net.sf.flatpack.DataSet;
11  import net.sf.flatpack.DefaultParserFactory;
12  import net.sf.flatpack.Parser;
13  
14  /**
15   * @author zepernick
16   * 
17   * TODO To change the template for this generated type comment go to Window -
18   * Preferences - Java - Code Style - Code Templates
19   */
20  public class DelimitedMultiLine {
21  
22      public static void main(final String[] args) throws Exception {
23          final String data = getDefaultDataFile();
24          try {
25              call(data);
26          } catch (final Exception e) {
27              // TODO Auto-generated catch block
28              e.printStackTrace();
29          }
30      }
31  
32      public static String getDefaultDataFile() {
33          return "PEOPLE-CommaDelimitedWithQualifierMultiLine.txt";
34      }
35  
36      public static void call(final String data) throws Exception {
37          // delimited by a comma
38          // text qualified by double quotes
39          // ignore first record
40          final Parser pzparser = DefaultParserFactory.getInstance().newDelimitedParser(new File(data), ',', '\"');
41          final DataSet ds = pzparser.parse();
42  
43          final String[] colNames = ds.getColumns();
44  
45          while (ds.next()) {
46              for (int i = 0; i < colNames.length; i++) {
47                  System.out.println("COLUMN NAME: " + colNames[i] + " VALUE: " + ds.getString(colNames[i]));
48              }
49  
50              System.out.println("===========================================================================");
51          }
52  
53          if (ds.getErrors() != null && ds.getErrors().size() > 0) {
54              System.out.println("FOUND ERRORS IN FILE");
55          }
56  
57      }
58  }