Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 155561052C for ; Tue, 30 Jul 2013 14:51:06 +0000 (UTC) Received: (qmail 48089 invoked by uid 500); 30 Jul 2013 14:51:05 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 47925 invoked by uid 500); 30 Jul 2013 14:51:04 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 47913 invoked by uid 99); 30 Jul 2013 14:51:04 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 30 Jul 2013 14:51:04 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 30 Jul 2013 14:51:03 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 44B8423888E7; Tue, 30 Jul 2013 14:50:43 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1508475 - in /commons/proper/csv/trunk/src/main/java/org/apache/commons/csv: CSVParser.java Lexer.java Date: Tue, 30 Jul 2013 14:50:43 -0000 To: commits@commons.apache.org From: ggregory@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20130730145043.44B8423888E7@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 { +public class CSVParser implements Iterable, Closeable { private final Lexer lexer; private final Map 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. *

@@ -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(); + } + } }