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 2013/07/30 16:50:43 UTC
svn commit: r1508475 - in
/commons/proper/csv/trunk/src/main/java/org/apache/commons/csv:
CSVParser.java Lexer.java
Author: ggregory
Date: Tue Jul 30 14:50:42 2013
New Revision: 1508475
URL: http://svn.apache.org/r1508475
Log:
Allow a caller to close the parser before reading all records and free resources. The parser and lexer now implement java.io.Closeable.
Modified:
commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVParser.java
commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/Lexer.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=1508475&r1=1508474&r2=1508475&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 Tue Jul 30 14:50:42 2013
@@ -19,6 +19,7 @@ package org.apache.commons.csv;
import static org.apache.commons.csv.Token.Type.TOKEN;
+import java.io.Closeable;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
@@ -80,7 +81,7 @@ import java.util.NoSuchElementException;
*
* @version $Id$
*/
-public class CSVParser implements Iterable<CSVRecord> {
+public class CSVParser implements Iterable<CSVRecord>, Closeable {
private final Lexer lexer;
private final Map<String, Integer> headerMap;
@@ -234,6 +235,15 @@ public class CSVParser implements Iterab
}}
/**
+ * Closes resources.
+ */
+ public void close() throws IOException {
+ if (lexer != null) {
+ lexer.close();
+ }
+ }
+
+ /**
* Parses the CSV input according to the given format and returns the content as an array of {@link CSVRecord}
* entries.
* <p/>
@@ -326,4 +336,5 @@ public class CSVParser implements Iterab
}
};
}
+
}
Modified: commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/Lexer.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/Lexer.java?rev=1508475&r1=1508474&r2=1508475&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/Lexer.java (original)
+++ commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/Lexer.java Tue Jul 30 14:50:42 2013
@@ -25,6 +25,7 @@ import static org.apache.commons.csv.Con
import static org.apache.commons.csv.Constants.TAB;
import static org.apache.commons.csv.Constants.UNDEFINED;
+import java.io.Closeable;
import java.io.IOException;
/**
@@ -32,7 +33,7 @@ import java.io.IOException;
*
* @version $Id$
*/
-abstract class Lexer {
+abstract class Lexer implements Closeable {
/**
* Constant char to use for disabling comments, escapes and encapsulation. The value -2 is used because it
@@ -191,7 +192,15 @@ abstract class Lexer {
return c == delimiter ||
c == escape ||
c == quoteChar ||
- c == commmentStart
- ;
+ c == commmentStart;
}
+
+ /**
+ * Closes resources.
+ */
+ public void close() throws IOException {
+ if (in != null) {
+ in.close();
+ }
+ }
}