Skip to content

Commit 33cf289

Browse files
committed
Remove factory methods for creating CSVParsers for classpath resources
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1513994 13f79535-47bb-0310-9956-ffa450edef68
1 parent 817561f commit 33cf289

3 files changed

Lines changed: 9 additions & 77 deletions

File tree

src/main/java/org/apache/commons/csv/CSVParser.java

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -107,59 +107,6 @@ public static CSVParser parse(File file, final CSVFormat format) throws IOExcept
107107
return new CSVParser(new FileReader(file), format);
108108
}
109109

110-
/**
111-
* Creates a parser for the given resource.
112-
*
113-
* <p>
114-
* If you do not read all records from the given source, you should call {@link #close()} on the parser.
115-
* </p>
116-
*
117-
* @param resource
118-
* a resource path
119-
* @param charset
120-
* the charset for the resource
121-
* @param classLoader
122-
* the class loader to load the resource.
123-
* @param format
124-
* the CSVFormat used for CSV parsing
125-
* @return a new parser
126-
* @throws IOException
127-
* If an I/O error occurs
128-
*/
129-
public static CSVParser parse(String resource, Charset charset, ClassLoader classLoader,
130-
final CSVFormat format) throws IOException {
131-
final URL url = classLoader.getResource(resource);
132-
if (url == null) {
133-
throw new IllegalArgumentException("Resource cannot be found: " + resource);
134-
}
135-
return parse(url, charset, format);
136-
}
137-
138-
/**
139-
* Creates a parser for the given resource.
140-
*
141-
* <p>
142-
* If you do not read all records from the given source, you should call {@link #close()} on the parser.
143-
* </p>
144-
*
145-
* @param resource
146-
* a resource path
147-
* @param charset
148-
* the charset for the resource
149-
* @param format
150-
* the CSVFormat used for CSV parsing
151-
* @return a new parser
152-
* @throws IOException
153-
* If an I/O error occurs
154-
*/
155-
public static CSVParser parse(String resource, Charset charset, final CSVFormat format) throws IOException {
156-
final URL url = ClassLoader.getSystemResource(resource);
157-
if (url == null) {
158-
throw new IllegalArgumentException("System resource cannot be found: " + resource);
159-
}
160-
return parse(url, charset, format);
161-
}
162-
163110
/**
164111
* Creates a parser for the given {@link String}.
165112
*
@@ -213,25 +160,6 @@ public static CSVParser parse(URL url, Charset charset, final CSVFormat format)
213160

214161
private final Token reusableToken = new Token();
215162

216-
/**
217-
* CSV parser using the default format {@link CSVFormat#DEFAULT}.
218-
*
219-
* <p>
220-
* If you do not read all records from the given {@code reader}, you should call {@link #close()} on the parser,
221-
* unless you close the {@code reader}.
222-
* </p>
223-
*
224-
* @param input
225-
* a Reader containing "csv-formatted" input
226-
* @throws IllegalArgumentException
227-
* thrown if the parameters of the format are inconsistent
228-
* @throws IOException
229-
* If an I/O error occurs
230-
*/
231-
public CSVParser(final Reader input) throws IOException {
232-
this(input, CSVFormat.DEFAULT);
233-
}
234-
235163
/**
236164
* Customized CSV parser using the given {@link CSVFormat}
237165
*

src/test/java/org/apache/commons/csv/CSVFileParserTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.io.FileReader;
2929
import java.io.FilenameFilter;
3030
import java.io.IOException;
31+
import java.net.URL;
3132
import java.nio.charset.Charset;
3233
import java.util.ArrayList;
3334
import java.util.Collection;
@@ -126,7 +127,7 @@ public void testCSVFile() throws Exception {
126127
}
127128

128129
@Test
129-
public void testCSVResource() throws Exception {
130+
public void testCSVUrl() throws Exception {
130131
String line = readTestData();
131132
assertNotNull("file must contain config line", line);
132133
final String[] split = line.split(" ");
@@ -153,8 +154,8 @@ public void testCSVResource() throws Exception {
153154
assertEquals(testName + " Expected format ", line, format.toString());
154155

155156
// Now parse the file and compare against the expected results
156-
final CSVParser parser = CSVParser.parse("CSVFileParser/" + split[0], Charset.forName("UTF-8"),
157-
this.getClass().getClassLoader(), format);
157+
URL resource = ClassLoader.getSystemResource("CSVFileParser/" + split[0]);
158+
final CSVParser parser = CSVParser.parse(resource, Charset.forName("UTF-8"), format);
158159
for (final CSVRecord record : parser) {
159160
String parsed = record.toString();
160161
if (checkComments) {

src/test/java/org/apache/commons/csv/FercGovTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.apache.commons.csv;
1818

1919
import java.io.IOException;
20+
import java.net.URL;
2021
import java.nio.charset.Charset;
2122
import java.util.List;
2223

@@ -42,7 +43,8 @@ private enum ContractColumnNames {
4243

4344
@Test
4445
public void testContractFile() throws IOException {
45-
final CSVParser parser = CSVParser.parse("ferc.gov/contract.txt", US_ASCII,
46+
URL contractData = ClassLoader.getSystemClassLoader().getResource("ferc.gov/contract.txt");
47+
final CSVParser parser = CSVParser.parse(contractData, US_ASCII,
4648
CSVFormat.DEFAULT.withHeader());
4749
try {
4850
final List<CSVRecord> records = parser.getRecords();
@@ -65,7 +67,8 @@ record = records.get(records.size() - 1);
6567

6668
@Test
6769
public void testTransactionFile() throws IOException {
68-
final CSVParser parser = CSVParser.parse("ferc.gov/transaction.txt", US_ASCII,
70+
URL transactionData = ClassLoader.getSystemClassLoader().getResource("ferc.gov/transaction.txt");
71+
final CSVParser parser = CSVParser.parse(transactionData, US_ASCII,
6972
CSVFormat.DEFAULT.withHeader());
7073
try {
7174
final List<CSVRecord> records = parser.getRecords();

0 commit comments

Comments
 (0)