You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by br...@apache.org on 2013/08/14 20:07:13 UTC

svn commit: r1513994 - 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/FercGovTest.java

Author: britter
Date: Wed Aug 14 18:07:13 2013
New Revision: 1513994

URL: http://svn.apache.org/r1513994
Log:
Remove factory methods for creating CSVParsers for classpath resources

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/FercGovTest.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=1513994&r1=1513993&r2=1513994&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 Wed Aug 14 18:07:13 2013
@@ -108,59 +108,6 @@ public final class CSVParser implements 
     }
 
     /**
-     * Creates a parser for the given resource.
-     *
-     * <p>
-     * If you do not read all records from the given source, you should call {@link #close()} on the parser.
-     * </p>
-     *
-     * @param resource
-     *            a resource path
-     * @param charset
-     *            the charset for the resource
-     * @param classLoader
-     *            the class loader to load the resource.
-     * @param format
-     *            the CSVFormat used for CSV parsing
-     * @return a new parser
-     * @throws IOException
-     *             If an I/O error occurs
-     */
-    public static CSVParser parse(String resource, Charset charset, ClassLoader classLoader,
-            final CSVFormat format) throws IOException {
-        final URL url = classLoader.getResource(resource);
-        if (url == null) {
-            throw new IllegalArgumentException("Resource cannot be found: " + resource);
-        }
-        return parse(url, charset, format);
-    }
-
-    /**
-     * Creates a parser for the given resource.
-     *
-     * <p>
-     * If you do not read all records from the given source, you should call {@link #close()} on the parser.
-     * </p>
-     *
-     * @param resource
-     *            a resource path
-     * @param charset
-     *            the charset for the resource
-     * @param format
-     *            the CSVFormat used for CSV parsing
-     * @return a new parser
-     * @throws IOException
-     *             If an I/O error occurs
-     */
-    public static CSVParser parse(String resource, Charset charset, final CSVFormat format) throws IOException {
-        final URL url = ClassLoader.getSystemResource(resource);
-        if (url == null) {
-            throw new IllegalArgumentException("System resource cannot be found: " + resource);
-        }
-        return parse(url, charset, format);
-    }
-
-    /**
      * Creates a parser for the given {@link String}.
      *
      * @param string
@@ -214,25 +161,6 @@ public final class CSVParser implements 
     private final Token reusableToken = new Token();
 
     /**
-     * CSV parser using the default format {@link CSVFormat#DEFAULT}.
-     *
-     * <p>
-     * If you do not read all records from the given {@code reader}, you should call {@link #close()} on the parser,
-     * unless you close the {@code reader}.
-     * </p>
-     *
-     * @param input
-     *            a Reader containing "csv-formatted" input
-     * @throws IllegalArgumentException
-     *             thrown if the parameters of the format are inconsistent
-     * @throws IOException
-     *             If an I/O error occurs
-     */
-    public CSVParser(final Reader input) throws IOException {
-        this(input, CSVFormat.DEFAULT);
-    }
-
-    /**
      * Customized CSV parser using the given {@link CSVFormat}
      *
      * <p>

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=1513994&r1=1513993&r2=1513994&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 Wed Aug 14 18:07:13 2013
@@ -28,6 +28,7 @@ import java.io.FileNotFoundException;
 import java.io.FileReader;
 import java.io.FilenameFilter;
 import java.io.IOException;
+import java.net.URL;
 import java.nio.charset.Charset;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -126,7 +127,7 @@ public class CSVFileParserTest {
     }
 
     @Test
-    public void testCSVResource() throws Exception {
+    public void testCSVUrl() throws Exception {
         String line = readTestData();
         assertNotNull("file must contain config line", line);
         final String[] split = line.split(" ");
@@ -153,8 +154,8 @@ public class CSVFileParserTest {
         assertEquals(testName + " Expected format ", line, format.toString());
 
         // Now parse the file and compare against the expected results
-        final CSVParser parser = CSVParser.parse("CSVFileParser/" + split[0], Charset.forName("UTF-8"),
-                this.getClass().getClassLoader(), format);
+        URL resource = ClassLoader.getSystemResource("CSVFileParser/" + split[0]);
+        final CSVParser parser = CSVParser.parse(resource, Charset.forName("UTF-8"), format);
         for (final CSVRecord record : parser) {
             String parsed = record.toString();
             if (checkComments) {

Modified: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/FercGovTest.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/FercGovTest.java?rev=1513994&r1=1513993&r2=1513994&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/FercGovTest.java (original)
+++ commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/FercGovTest.java Wed Aug 14 18:07:13 2013
@@ -17,6 +17,7 @@
 package org.apache.commons.csv;
 
 import java.io.IOException;
+import java.net.URL;
 import java.nio.charset.Charset;
 import java.util.List;
 
@@ -42,7 +43,8 @@ public class FercGovTest {
 
     @Test
     public void testContractFile() throws IOException {
-        final CSVParser parser = CSVParser.parse("ferc.gov/contract.txt", US_ASCII,
+        URL contractData = ClassLoader.getSystemClassLoader().getResource("ferc.gov/contract.txt");
+        final CSVParser parser = CSVParser.parse(contractData, US_ASCII,
                 CSVFormat.DEFAULT.withHeader());
         try {
             final List<CSVRecord> records = parser.getRecords();
@@ -65,7 +67,8 @@ public class FercGovTest {
 
     @Test
     public void testTransactionFile() throws IOException {
-        final CSVParser parser = CSVParser.parse("ferc.gov/transaction.txt", US_ASCII,
+        URL transactionData = ClassLoader.getSystemClassLoader().getResource("ferc.gov/transaction.txt");
+        final CSVParser parser = CSVParser.parse(transactionData, US_ASCII,
                 CSVFormat.DEFAULT.withHeader());
         try {
             final List<CSVRecord> records = parser.getRecords();