Skip to content

Commit 6870022

Browse files
committed
The class implements Closeable.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1398278 13f79535-47bb-0310-9956-ffa450edef68
1 parent 4aee321 commit 6870022

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import static org.apache.commons.csv.Constants.LF;
2424
import static org.apache.commons.csv.Constants.SP;
2525

26+
import java.io.Closeable;
2627
import java.io.Flushable;
2728
import java.io.IOException;
2829
import java.sql.ResultSet;
@@ -33,7 +34,7 @@
3334
*
3435
* @version $Id: $
3536
*/
36-
public class CSVPrinter implements Flushable {
37+
public class CSVPrinter implements Flushable, Closeable {
3738

3839
/** The place that the values get written. */
3940
private final Appendable out;
@@ -387,4 +388,10 @@ public void printRecords(ResultSet resultSet) throws SQLException, IOException {
387388
println();
388389
}
389390
}
391+
392+
public void close() throws IOException {
393+
if (out instanceof Closeable) {
394+
((Closeable) out).close();
395+
}
396+
}
390397
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public void doOneRandom(final CSVFormat format) throws Exception {
7777
}
7878

7979
printer.flush();
80+
printer.close();
8081
final String result = sw.toString();
8182
// System.out.println("### :" + printable(result));
8283

0 commit comments

Comments
 (0)