[jacli commit] r18 - wiki

0 views
Skip to first unread message

codesite...@google.com

unread,
Jun 19, 2008, 8:40:05 AM6/19/08
to fant...@googlegroups.com
Author: maomaode
Date: Thu Jun 19 05:39:35 2008
New Revision: 18

Added:
wiki/
wiki/JaCliWithOpenCSV.wiki

Log:
Created wiki page through web user interface.

Added: wiki/JaCliWithOpenCSV.wiki
==============================================================================
--- (empty file)
+++ wiki/JaCliWithOpenCSV.wiki Thu Jun 19 05:39:35 2008
@@ -0,0 +1,39 @@
+#summary One-sentence summary of this page.
+#labels csv,opencsv,jacli
+
+= Introduction =
+
+Combine two tools, you can parse the CSV files into a Collection of Beans
+
+
+= Details =
+
+{{{
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.Collection;
+
+import au.com.bytecode.opencsv.CSVReader;
+import com.google.jacli.CommandLineParser;
+
+public final class CSVParser {
+ private CSVParser() {
+ }
+
+ public static <T> void parse(final Class<T> beanClz, final File
csvFile, final Collection<T>results)
+ throws InstantiationException, IllegalAccessException,
FileNotFoundException, IOException {
+ CSVReader reader = new CSVReader(new FileReader(csvFile));
+ String [] nextLine;
+ while ((nextLine = reader.readNext()) != null) {
+ T bean = null;
+ bean = beanClz.newInstance();
+ if (bean != null) {
+ CommandLineParser.parse(bean, nextLine);
+ results.add(bean);
+ }
+ }
+ }
+}
+}}}
\ No newline at end of file

Reply all
Reply to author
Forward
0 new messages