You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2014/06/16 17:39:52 UTC

svn commit: r1602901 - in /commons/proper/csv/trunk/src: main/java/org/apache/commons/csv/CSVParser.java test/java/org/apache/commons/csv/CSVFileParserTest.java test/java/org/apache/commons/csv/CSVParserTest.java

Author: ggregory
Date: Mon Jun 16 15:39:52 2014
New Revision: 1602901

URL: http://svn.apache.org/r1602901
Log:
org.apache.commons.csv.CSVParser.parse(File, Charset, CSVFormat) is now like org.apache.commons.csv.CSVParser.parse(URL, Charset, CSVFormat): You must pass in a Charset.

Modified:
    commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVParser.java
    commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFileParserTest.java
    commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java

Modified: commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVParser.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVParser.java?rev=1602901&r1=1602900&r2=1602901&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVParser.java (original)
+++ commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVParser.java Mon Jun 16 15:39:52 2014
@@ -17,10 +17,9 @@
 
 package org.apache.commons.csv;
 
-import static org.apache.commons.csv.Token.Type.TOKEN;
-
 import java.io.Closeable;
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
@@ -37,6 +36,8 @@ import java.util.List;
 import java.util.Map;
 import java.util.NoSuchElementException;
 
+import static org.apache.commons.csv.Token.Type.*;
+
 /**
  * Parses CSV files according to the specified format.
  *
@@ -50,7 +51,7 @@ import java.util.NoSuchElementException;
  * There are several static factory methods that can be used to create instances for various types of resources:
  * </p>
  * <ul>
- *     <li>{@link #parse(java.io.File, CSVFormat)}</li>
+ *     <li>{@link #parse(java.io.File, Charset, CSVFormat)}</li>
  *     <li>{@link #parse(String, CSVFormat)}</li>
  *     <li>{@link #parse(java.net.URL, java.nio.charset.Charset, CSVFormat)}</li>
  * </ul>
@@ -142,6 +143,8 @@ public final class CSVParser implements 
      *
      * @param file
      *            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
@@ -150,11 +153,11 @@ public final class CSVParser implements 
      * @throws IOException
      *             If an I/O error occurs
      */
-    public static CSVParser parse(final File file, final CSVFormat format) throws IOException {
+    public static CSVParser parse(final File file, Charset charset, final CSVFormat format) throws IOException {
         Assertions.notNull(file, "file");
         Assertions.notNull(format, "format");
-
-        return new CSVParser(new FileReader(file), format);
+        // Use the default Charset explicitly
+        return new CSVParser(new InputStreamReader(new FileInputStream(file), charset), format);
     }
 
     /**

Modified: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFileParserTest.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFileParserTest.java?rev=1602901&r1=1602900&r2=1602901&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFileParserTest.java (original)
+++ commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFileParserTest.java Mon Jun 16 15:39:52 2014
@@ -112,7 +112,7 @@ public class CSVFileParserTest {
 
         // Now parse the file and compare against the expected results
         // We use a buffered reader internally so no need to create one here.
-        final CSVParser parser = CSVParser.parse(new File(BASE, split[0]), format);
+        final CSVParser parser = CSVParser.parse(new File(BASE, split[0]), Charset.defaultCharset(), format);
         for(final CSVRecord record : parser) {
             String parsed = record.toString();
             if (checkComments) {

Modified: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java?rev=1602901&r1=1602900&r2=1602901&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java (original)
+++ commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java Mon Jun 16 15:39:52 2014
@@ -806,12 +806,12 @@ public class CSVParserTest {
 
     @Test(expected = IllegalArgumentException.class)
     public void testParseFileNullFormat() throws Exception {
-        CSVParser.parse(new File(""), null);
+        CSVParser.parse(new File(""), Charset.defaultCharset(), null);
     }
 
     @Test(expected = IllegalArgumentException.class)
     public void testParseNullFileFormat() throws Exception {
-        CSVParser.parse((File) null, CSVFormat.DEFAULT);
+        CSVParser.parse((File) null, Charset.defaultCharset(), CSVFormat.DEFAULT);
     }
 
     @Test(expected = IllegalArgumentException.class)
@@ -821,7 +821,7 @@ public class CSVParserTest {
 
     @Test(expected = IllegalArgumentException.class)
     public void testParseNullUrlCharsetFormat() throws Exception {
-        CSVParser.parse(null, Charset.defaultCharset(), CSVFormat.DEFAULT);
+        CSVParser.parse((File) null, Charset.defaultCharset(), CSVFormat.DEFAULT);
     }
 
     @Test(expected = IllegalArgumentException.class)