commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject commons-csv git commit: [CSV-192] Add convenience API CSVParser.parse(Path, Charset, CSVFormat)
Date Sat, 30 Jul 2016 18:16:34 GMT
Repository: commons-csv
Updated Branches:
  refs/heads/master 81f24008c -> 9b37b1eb1


[CSV-192] Add convenience API CSVParser.parse(Path, Charset, CSVFormat)

Project: http://git-wip-us.apache.org/repos/asf/commons-csv/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-csv/commit/9b37b1eb
Tree: http://git-wip-us.apache.org/repos/asf/commons-csv/tree/9b37b1eb
Diff: http://git-wip-us.apache.org/repos/asf/commons-csv/diff/9b37b1eb

Branch: refs/heads/master
Commit: 9b37b1eb1f53e107c83e60232ec39d6174591f24
Parents: 81f2400
Author: Gary Gregory <ggregory@apache.org>
Authored: Sat Jul 30 11:16:31 2016 -0700
Committer: Gary Gregory <ggregory@apache.org>
Committed: Sat Jul 30 11:16:31 2016 -0700

----------------------------------------------------------------------
 src/changes/changes.xml                         |  1 +
 .../java/org/apache/commons/csv/CSVParser.java  | 28 ++++++++++++++++++++
 2 files changed, 29 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-csv/blob/9b37b1eb/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 1c9e956..eb7df9e 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -43,6 +43,7 @@
       <action issue="CSV-189" type="add" dev="ggregory" due-to="Peter Holzwarth, Gary
Gregory">CSVParser: Add factory method accepting InputStream.</action>
       <action issue="CSV-190" type="add" dev="ggregory" due-to="Gary Gregory">Add convenience
API CSVFormat.print(File, Charset)</action>
       <action issue="CSV-191" type="add" dev="ggregory" due-to="Gary Gregory">Add convenience
API CSVFormat.print(Path, Charset)</action>
+      <action issue="CSV-192" type="add" dev="ggregory" due-to="Gary Gregory">Add convenience
API CSVParser.parse(Path, Charset, CSVFormat)</action>
     </release>
     <release version="1.4" date="2016-05-28" description="Feature and bug fix release">
       <action issue="CSV-181" type="update" dev="ggregory" due-to="Gary Gregory">Make
CSVPrinter.print(Object) GC-free.</action>

http://git-wip-us.apache.org/repos/asf/commons-csv/blob/9b37b1eb/src/main/java/org/apache/commons/csv/CSVParser.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/csv/CSVParser.java b/src/main/java/org/apache/commons/csv/CSVParser.java
index 8550342..1331836 100644
--- a/src/main/java/org/apache/commons/csv/CSVParser.java
+++ b/src/main/java/org/apache/commons/csv/CSVParser.java
@@ -30,6 +30,7 @@ import java.io.StringReader;
 import java.io.UnsupportedEncodingException;
 import java.net.URL;
 import java.nio.charset.Charset;
+import java.nio.file.Path;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Iterator;
@@ -193,6 +194,33 @@ public final class CSVParser implements Iterable<CSVRecord>, Closeable
{
     }
 
     /**
+     * Creates a parser for the given {@link File}.
+     *
+     * <p><strong>Note:</strong> This method internally creates a FileReader
using
+     * {@link java.io.FileReader#FileReader(java.io.File)} which in turn relies on the default
encoding of the JVM that
+     * is executing the code. If this is insufficient create a URL to the file and use
+     * {@link #parse(URL, Charset, CSVFormat)}</p>
+     *
+     * @param path
+     *            a CSV file. Must not be null.
+     * @param charset
+     *            A charset
+     * @param format
+     *            the CSVFormat used for CSV parsing. Must not be null.
+     * @return a new parser
+     * @throws IllegalArgumentException
+     *             If the parameters of the format are inconsistent or if either file or
format are null.
+     * @throws IOException
+     *             If an I/O error occurs
+     * @since 1.5
+     */
+    public static CSVParser parse(final Path path, final Charset charset, final CSVFormat
format) throws IOException {
+        Assertions.notNull(path, "path");
+        Assertions.notNull(format, "format");
+        return parse(path.toFile(), charset, format);
+    }
+
+    /**
      * Creates a CSV parser using the given {@link CSVFormat}
      *
      * <p>


Mime
View raw message