Commit dc81ee67 authored by Emmanuel Bourg's avatar Emmanuel Bourg

New upstream version 1.6

parent d0e484d8
### https://raw.github.com/github/gitignore/14b7566ce157ce95b07006466bacee160f242284/maven.gitignore
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
/.classpath
/.project
/.settings/
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
language: java
sudo: false
script:
- mvn
jdk:
- openjdk7
- oraclejdk8
- oraclejdk9
after_success:
- mvn -B -V -Ptravis-jacoco clean test jacoco:report coveralls:report
<!---
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!---
+======================================================================+
|**** ****|
|**** THIS FILE IS GENERATED BY THE COMMONS BUILD PLUGIN ****|
|**** DO NOT EDIT DIRECTLY ****|
|**** ****|
+======================================================================+
| TEMPLATE FILE: contributing-md-template.md |
| commons-build-plugin/trunk/src/main/resources/commons-xdoc-templates |
+======================================================================+
| |
| 1) Re-generate using: mvn commons:contributing-md |
| |
| 2) Set the following properties in the component's pom: |
| - commons.jira.id (required, alphabetic, upper case) |
| |
| 3) Example Properties |
| |
| <properties> |
| <commons.jira.id>MATH</commons.jira.id> |
| </properties> |
| |
+======================================================================+
--->
Contributing to Apache Commons CSV
======================
You have found a bug or you have an idea for a cool new feature? Contributing code is a great way to give something back to
the open source community. Before you dig right into the code there are a few guidelines that we need contributors to
follow so that we can have a chance of keeping on top of things.
Getting Started
---------------
+ Make sure you have a [JIRA account](https://issues.apache.org/jira/).
+ Make sure you have a [GitHub account](https://github.com/signup/free).
+ If you're planning to implement a new feature it makes sense to discuss your changes on the [dev list](https://commons.apache.org/mail-lists.html) first. This way you can make sure you're not wasting your time on something that isn't considered to be in Apache Commons CSV's scope.
+ Submit a [Jira Ticket][jira] for your issue, assuming one does not already exist.
+ Clearly describe the issue including steps to reproduce when it is a bug.
+ Make sure you fill in the earliest version that you know has the issue.
+ Find the corresponding [repository on GitHub](https://github.com/apache/?query=commons-),
[fork](https://help.github.com/articles/fork-a-repo/) and check out your forked repository.
Making Changes
--------------
+ Create a _topic branch_ for your isolated work.
* Usually you should base your branch on the `master` or `trunk` branch.
* A good topic branch name can be the JIRA bug id plus a keyword, e.g. `CSV-123-InputStream`.
* If you have submitted multiple JIRA issues, try to maintain separate branches and pull requests.
+ Make commits of logical units.
* Make sure your commit messages are meaningful and in the proper format. Your commit message should contain the key of the JIRA issue.
* e.g. `CSV-123: Close input stream earlier`
+ Respect the original code style:
+ Only use spaces for indentation.
+ Create minimal diffs - disable _On Save_ actions like _Reformat Source Code_ or _Organize Imports_. If you feel the source code should be reformatted create a separate PR for this change first.
+ Check for unnecessary whitespace with `git diff` -- check before committing.
+ Make sure you have added the necessary tests for your changes, typically in `src/test/java`.
+ Run all the tests with `mvn clean verify` to assure nothing else was accidentally broken.
Making Trivial Changes
----------------------
The JIRA tickets are used to generate the changelog for the next release.
For changes of a trivial nature to comments and documentation, it is not always necessary to create a new ticket in JIRA.
In this case, it is appropriate to start the first line of a commit with '(doc)' instead of a ticket number.
Submitting Changes
------------------
+ Sign and submit the Apache [Contributor License Agreement][cla] if you haven't already.
* Note that small patches & typical bug fixes do not require a CLA as
clause 5 of the [Apache License](https://www.apache.org/licenses/LICENSE-2.0.html#contributions)
covers them.
+ Push your changes to a topic branch in your fork of the repository.
+ Submit a _Pull Request_ to the corresponding repository in the `apache` organization.
* Verify _Files Changed_ shows only your intended changes and does not
include additional files like `target/*.class`
+ Update your JIRA ticket and include a link to the pull request in the ticket.
If you prefer to not use GitHub, then you can instead use
`git format-patch` (or `svn diff`) and attach the patch file to the JIRA issue.
Additional Resources
--------------------
+ [Contributing patches](https://commons.apache.org/patches.html)
+ [Apache Commons CSV JIRA project page][jira]
+ [Contributor License Agreement][cla]
+ [General GitHub documentation](https://help.github.com/)
+ [GitHub pull request documentation](https://help.github.com/articles/creating-a-pull-request/)
+ [Apache Commons Twitter Account](https://twitter.com/ApacheCommons)
+ `#apache-commons` IRC channel on `irc.freenode.net`
[cla]:https://www.apache.org/licenses/#clas
[jira]:https://issues.apache.org/jira/browse/CSV
Apache Commons CSV
Copyright 2005-2017 The Apache Software Foundation
Copyright 2005-2018 The Apache Software Foundation
This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).
<!---
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!---
+======================================================================+
|**** ****|
|**** THIS FILE IS GENERATED BY THE COMMONS BUILD PLUGIN ****|
|**** DO NOT EDIT DIRECTLY ****|
|**** ****|
+======================================================================+
| TEMPLATE FILE: readme-md-template.md |
| commons-build-plugin/trunk/src/main/resources/commons-xdoc-templates |
+======================================================================+
| |
| 1) Re-generate using: mvn commons:readme-md |
| |
| 2) Set the following properties in the component's pom: |
| - commons.componentid (required, alphabetic, lower case) |
| - commons.release.version (required) |
| |
| 3) Example Properties |
| |
| <properties> |
| <commons.componentid>math</commons.componentid> |
| <commons.release.version>1.2</commons.release.version> |
| </properties> |
| |
+======================================================================+
--->
Apache Commons CSV
===================
[![Build Status](https://travis-ci.org/apache/commons-csv.svg)](https://travis-ci.org/apache/commons-csv)
[![Coverage Status](https://coveralls.io/repos/apache/commons-csv/badge.svg)](https://coveralls.io/r/apache/commons-csv)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.apache.commons/commons-csv/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.apache.commons/commons-csv/)
[![Javadocs](https://javadoc.io/badge/org.apache.commons/commons-csv/1.6.svg)](https://javadoc.io/doc/org.apache.commons/commons-csv/1.6)
The Apache Commons CSV library provides a simple interface for reading and writing
CSV files of various types.
Documentation
-------------
More information can be found on the [Apache Commons CSV homepage](https://commons.apache.org/proper/commons-csv).
The [Javadoc](https://commons.apache.org/proper/commons-csv/javadocs/api-release) can be browsed.
Questions related to the usage of Apache Commons CSV should be posted to the [user mailing list][ml].
Where can I get the latest release?
-----------------------------------
You can download source and binaries from our [download page](https://commons.apache.org/proper/commons-csv/download_csv.cgi).
Alternatively you can pull it from the central Maven repositories:
```xml
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
<version>1.6</version>
</dependency>
```
Contributing
------------
We accept Pull Requests via GitHub. The [developer mailing list][ml] is the main channel of communication for contributors.
There are some guidelines which will make applying PRs easier for us:
+ No tabs! Please use spaces for indentation.
+ Respect the code style.
+ Create minimal diffs - disable on save actions like reformat source code or organize imports. If you feel the source code should be reformatted create a separate PR for this change.
+ Provide JUnit tests for your changes and make sure your changes don't break any existing tests by running ```mvn clean test```.
If you plan to contribute on a regular basis, please consider filing a [contributor license agreement](https://www.apache.org/licenses/#clas).
You can learn more about contributing via GitHub in our [contribution guidelines](CONTRIBUTING.md).
License
-------
This code is under the [Apache Licence v2](https://www.apache.org/licenses/LICENSE-2.0).
See the `NOTICE.txt` file for required notices and attributions.
Donations
---------
You like Apache Commons CSV? Then [donate back to the ASF](https://www.apache.org/foundation/contributing.html) to support the development.
Additional Resources
--------------------
+ [Apache Commons Homepage](https://commons.apache.org/)
+ [Apache Issue Tracker (JIRA)](https://issues.apache.org/jira/browse/CSV)
+ [Apache Commons Twitter Account](https://twitter.com/ApacheCommons)
+ `#apache-commons` IRC channel on `irc.freenode.org`
[ml]:https://commons.apache.org/mail-lists.html
Apache Commons CSV
Version 1.6
Release Notes
INTRODUCTION:
This document contains the release notes for the 1.6 version of
Apache Commons CSV. Commons CSV reads and writes files in variations of the
Comma Separated Value (CSV) format.
CSV requires at least Java 7.
The Apache Commons CSV library provides a simple interface for reading and
writing CSV files of various types.
Feature and bug fix release.
Changes in this version include:
NEW FEATURES
==============
o CSV-217: Add autoFlush option for CsvPrinter. PR #24.
Thanks to Korolyov Alexei.
o CSV-220: Add API org.apache.commons.csv.CSVFormat.withSystemRecordSeparator().
Thanks to Gary Gregory.
FIXED BUGS
============
o CSV-219: The behavior of quote char using is not similar as Excel does when
the first string contains CJK char(s). Thanks to Zhang Hongda.
o CSV-172: Don't quote cells just because they have UTF-8 encoded characters.
Thanks to Andrew Pennebaker.
o CSV-223: Inconsistency between Javadoc of CSVFormat DEFAULT EXCEL.
Thanks to Samuel Martin.
o CSV-209: Create CSVFormat.ORACLE preset. Thanks to Gary Gregory.
o CSV-224: Some multi-iterator parsing peek sequences incorrectly consume
elements. Thanks to David Warshaw.
o CSV-225: Parse method should avoid creating a redundant BufferedReader.
Thanks to Anson Schwabecher.
CHANGES
=========
o CSV-231: Add more documentation to CSVPrinter.
Have fun!
-Apache Commons CSV team
------------------------------------------------------------------------------
Apache Commons CSV
Version 1.5
Release Notes
......
......@@ -20,10 +20,10 @@
<parent>
<groupId>org.apache.commons</groupId>
<artifactId>commons-parent</artifactId>
<version>42</version>
<version>47</version>
</parent>
<artifactId>commons-csv</artifactId>
<version>1.5</version>
<version>1.6</version>
<name>Apache Commons CSV</name>
<url>http://commons.apache.org/proper/commons-csv/</url>
<description>
......@@ -38,16 +38,22 @@ CSV files of various types.
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
<version>2.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.6</version>
<version>3.8</version>
<scope>test</scope>
</dependency>
<dependency>
......@@ -128,7 +134,7 @@ CSV files of various types.
</distributionManagement>
<properties>
<commons.release.version>1.5</commons.release.version>
<commons.release.version>1.6</commons.release.version>
<commons.release.desc>(Java 7+)</commons.release.desc>
<!-- The RC version used in the staging repository URL. -->
<commons.rc.version>RC1</commons.rc.version>
......@@ -136,6 +142,7 @@ CSV files of various types.
<commons.module.name>org.apache.commons.csv</commons.module.name>
<commons.jira.id>CSV</commons.jira.id>
<commons.jira.pid>12313222</commons.jira.pid>
<project.inceptionYear>2005</project.inceptionYear>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<!-- Ensure copies work OK (can be removed later when this is in parent POM) -->
......@@ -146,6 +153,11 @@ CSV files of various types.
<checkstyle.version>2.17</checkstyle.version>
<checkstyle.header.file>${basedir}/LICENSE-header.txt</checkstyle.header.file>
<checkstyle.resourceExcludes>LICENSE.txt, NOTICE.txt</checkstyle.resourceExcludes>
<!-- Fix for COMMONSSITE-124 remove once commons-parent 48 has been released -->
<commons.scmPubUrl>https://svn.apache.org/repos/infra/websites/production/commons/content/proper/${project.artifactId}</commons.scmPubUrl>
<!-- Fix for COMMONSSITE-125 remove once commons-parent 48 has been released -->
<commons.osgi.symbolicName>org.apache.commons.${commons.componentid}</commons.osgi.symbolicName>
</properties>
<build>
......@@ -231,6 +243,45 @@ CSV files of various types.
</excludes>
</configuration>
</plugin>
<!--
calculate checksums of release artifacts for Apache dist area
-->
<plugin>
<groupId>net.nicoulaj.maven.plugins</groupId>
<artifactId>checksum-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>generate.checksums</id>
<phase>verify</phase>
<goals>
<goal>files</goal>
</goals>
</execution>
</executions>
<configuration>
<algorithms>
<algorithm>SHA-512</algorithm>
</algorithms>
<csvSummary>false</csvSummary>
<fileSets>
<fileSet>
<directory>${project.build.directory}</directory>
<includes>
<include>${project.artifactId}-${project.version}-src.zip</include>
<include>
${project.artifactId}-${project.version}-src.tar.gz
</include>
<include>${project.artifactId}-${project.version}-bin.zip</include>
<include>
${project.artifactId}-${project.version}-bin.tar.gz
</include>
</includes>
</fileSet>
</fileSets>
</configuration>
</plugin>
</plugins>
</build>
......@@ -265,7 +316,6 @@ CSV files of various types.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.4</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
......@@ -506,6 +556,17 @@ CSV files of various types.
</plugins>
</build>
</profile>
<profile>
<id>java9</id>
<activation>
<jdk>9</jdk>
</activation>
<properties>
<!-- coverall version 4.3.0 does not work with java 9, see https://github.com/trautonen/coveralls-maven-plugin/issues/112 -->
<coveralls.skip>true</coveralls.skip>
</properties>
</profile>
</profiles>
</project>
......@@ -38,7 +38,18 @@
<title>Release Notes</title>
</properties>
<body>
<release version="1.5" date="2017-08-26" description="Feature and bug fix release">
<release version="1.6" date="2018-09-22" description="Feature and bug fix release">
<action issue="CSV-231" type="update" dev="britter">Add more documentation to CSVPrinter.</action>
<action issue="CSV-217" type="add" dev="ggregory" due-to="Korolyov Alexei">Add autoFlush option for CsvPrinter. PR #24.</action>
<action issue="CSV-219" type="fix" dev="ggregory" due-to="Zhang Hongda">The behavior of quote char using is not similar as Excel does when the first string contains CJK char(s).</action>
<action issue="CSV-172" type="fix" dev="ggregory" due-to="Andrew Pennebaker">Don't quote cells just because they have UTF-8 encoded characters.</action>
<action issue="CSV-220" type="add" dev="ggregory" due-to="Gary Gregory">Add API org.apache.commons.csv.CSVFormat.withSystemRecordSeparator().</action>
<action issue="CSV-223" type="fix" dev="ggregory" due-to="Samuel Martin">Inconsistency between Javadoc of CSVFormat DEFAULT EXCEL.</action>
<action issue="CSV-209" type="fix" dev="ggregory" due-to="Gary Gregory">Create CSVFormat.ORACLE preset.</action>
<action issue="CSV-224" type="fix" dev="ggregory" due-to="David Warshaw">Some multi-iterator parsing peek sequences incorrectly consume elements.</action>
<action issue="CSV-225" type="fix" dev="ggregory" due-to="Anson Schwabecher">Parse method should avoid creating a redundant BufferedReader.</action>
</release>
<release version="1.5" date="2017-09-03" description="Feature and bug fix release">
<action issue="CSV-203" type="fix" dev="ggregory" due-to="Richard Wheeldon, Kai Paroth">withNullString value is printed without quotes when QuoteMode.ALL is specified; add QuoteMode.ALL_NON_NULL. PR #17.</action>
<action issue="CSV-194" type="fix" dev="ggregory" due-to="Marc Prud'hommeaux">Fix outdated comments about FileReader in CSVParser #13</action>
<action issue="CSV-193" type="fix" dev="ggregory" due-to="Matthias Wiehl">Fix incorrect method name 'withFirstRowAsHeader' in user guide.</action>
......
......@@ -30,7 +30,7 @@ final class Assertions {
// can not be instantiated
}
public static void notNull(final Object parameter, final String parameterName) {
static void notNull(final Object parameter, final String parameterName) {
if (parameter == null) {
throw new IllegalArgumentException("Parameter '" + parameterName + "' must not be null!");
}
......
......@@ -99,7 +99,7 @@ import java.util.TreeMap;
*
* <p>
* If the predefined formats don't match the format at hands, custom formats can be defined. More information about
* customising CSVFormats is available in {@link CSVFormat CSVFormat JavaDoc}.
* customising CSVFormats is available in {@link CSVFormat CSVFormat Javadoc}.
* </p>
*
* <h2>Parsing into memory</h2>
......@@ -203,7 +203,7 @@ public final class CSVParser implements Iterable<CSVRecord>, Closeable {
public static CSVParser parse(final Path path, final Charset charset, final CSVFormat format) throws IOException {
Assertions.notNull(path, "path");
Assertions.notNull(format, "format");
return parse(Files.newBufferedReader(path, charset), format);
return parse(Files.newInputStream(path), charset, format);
}
/**
......@@ -225,7 +225,7 @@ public final class CSVParser implements Iterable<CSVRecord>, Closeable {
* If there is a problem reading the header or skipping the first record
* @since 1.5
*/
public static CSVParser parse(Reader reader, final CSVFormat format) throws IOException {
public static CSVParser parse(final Reader reader, final CSVFormat format) throws IOException {
return new CSVParser(reader, format);
}
......@@ -286,6 +286,8 @@ public final class CSVParser implements Iterable<CSVRecord>, Closeable {
private final Lexer lexer;
private final CSVRecordIterator csvRecordIterator;
/** A record buffer for getRecord(). Grows as necessary and is reused. */
private final List<String> recordList = new ArrayList<>();
......@@ -353,6 +355,7 @@ public final class CSVParser implements Iterable<CSVRecord>, Closeable {
this.format = format;
this.lexer = new Lexer(format, new ExtendedBufferedReader(reader));
this.csvRecordIterator = new CSVRecordIterator();
this.headerMap = this.initializeHeader();
this.characterOffset = characterOffset;
this.recordNumber = recordNumber - 1;
......@@ -519,55 +522,57 @@ public final class CSVParser implements Iterable<CSVRecord>, Closeable {
*/
@Override
public Iterator<CSVRecord> iterator() {
return new Iterator<CSVRecord>() {
private CSVRecord current;
private CSVRecord getNextRecord() {
try {
return CSVParser.this.nextRecord();
} catch (final IOException e) {
throw new IllegalStateException(
e.getClass().getSimpleName() + " reading next record: " + e.toString(), e);
}
}
return csvRecordIterator;
}
@Override
public boolean hasNext() {
if (CSVParser.this.isClosed()) {
return false;
}
if (this.current == null) {
this.current = this.getNextRecord();
}
class CSVRecordIterator implements Iterator<CSVRecord> {
private CSVRecord current;
return this.current != null;
private CSVRecord getNextRecord() {
try {
return CSVParser.this.nextRecord();
} catch (final IOException e) {
throw new IllegalStateException(
e.getClass().getSimpleName() + " reading next record: " + e.toString(), e);
}
}
@Override
public CSVRecord next() {
if (CSVParser.this.isClosed()) {
throw new NoSuchElementException("CSVParser has been closed");
}
CSVRecord next = this.current;
this.current = null;
@Override
public boolean hasNext() {
if (CSVParser.this.isClosed()) {
return false;
}
if (this.current == null) {
this.current = this.getNextRecord();
}
if (next == null) {
// hasNext() wasn't called before
next = this.getNextRecord();
if (next == null) {
throw new NoSuchElementException("No more CSV records available");
}
}
return this.current != null;
}
return next;
@Override
public CSVRecord next() {
if (CSVParser.this.isClosed()) {
throw new NoSuchElementException("CSVParser has been closed");
}
CSVRecord next = this.current;
this.current = null;
@Override
public void remove() {
throw new UnsupportedOperationException();
if (next == null) {
// hasNext() wasn't called before
next = this.getNextRecord();
if (next == null) {
throw new NoSuchElementException("No more CSV records available");
}
}
};
}
return next;
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
};
/**
* Parses the next record from the current point in the stream.
......
......@@ -26,9 +26,44 @@ import java.io.Flushable;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;
/**
* Prints values in a CSV format.
* Prints values in a {@link CSVFormat CSV format}.
*
* <p>Values can be appended to the output by calling the {@link #print(Object)} method.
* Values are printed according to {@link String#valueOf(Object)}.
* To complete a record the {@link #println()} method has to be called.
* Comments can be appended by calling {@link #printComment(String)}.
* However a comment will only be written to the output if the {@link CSVFormat} supports comments.
* </p>
*
* <p>The printer also supports appending a complete record at once by calling {@link #printRecord(Object...)}
* or {@link #printRecord(Iterable)}.
* Furthermore {@link #printRecords(Object...)}, {@link #printRecords(Iterable)} and {@link #printRecords(ResultSet)}
* methods can be used to print several records at once.
* </p>
*
* <p>Example:</p>
*
* <pre>
* try (CSVPrinter printer = new CSVPrinter(new FileWriter("csv.txt"), CSVFormat.EXCEL)) {
* printer.printRecord("id", "userName", "firstName", "lastName", "birthday");
* printer.printRecord(1, "john73", "John", "Doe", LocalDate.of(1973, 9, 15));
* printer.println();
* printer.printRecord(2, "mary", "Mary", "Meyer", LocalDate.of(1985, 3, 29));
* } catch (IOException ex) {
* ex.printStackTrace();
* }
* </pre>
*
* <p>This code will write the following to csv.txt:</p>
* <pre>
* id,userName,firstName,lastName,birthday
* 1,john73,John,Doe,1973-09-15
*
* 2,mary,Mary,Meyer,1985-03-29
* </pre>
*/
public final class CSVPrinter implements Flushable, Closeable {
......@@ -81,6 +116,21 @@ public final class CSVPrinter implements Flushable, Closeable {
@Override
public void close() throws IOException {
close(false);
}
/**
* Closes the underlying stream with an optional flush first.
* @param flush whether to flush before the actual close.
*
* @throws IOException
* If an I/O error occurs
* @since 1.6
*/
public void close(final boolean flush) throws IOException {
if (flush || format.getAutoFlush()) {
flush();
}
if (out instanceof Closeable) {
((Closeable) out).close();
}
......@@ -125,11 +175,17 @@ public final class CSVPrinter implements Flushable, Closeable {
* Prints a comment on a new line among the delimiter separated values.
*
* <p>
* Comments will always begin on a new line and occupy a least one full line. The character specified to start
* Comments will always begin on a new line and occupy at least one full line. The character specified to start
* comments and a space will be inserted at the beginning of each new line in the comment.
* </p>
*
* <p>
* If comments are disabled in the current CSV format this method does nothing.
* </p>
*
* <p>This method detects line breaks inside the comment string and inserts {@link CSVFormat#getRecordSeparator()}
* to start a new line of the comment. Note that this might produce unexpected results for formats that do not use
* line breaks as record separator.</p>
*
* @param comment
* the comment to output
......@@ -306,15 +362,7 @@ public final class CSVPrinter implements Flushable, Closeable {
* If an I/O error occurs
*/
public void printRecords(final Object... values) throws IOException {
for (final Object value : values) {
if (value instanceof Object[]) {
this.printRecord((Object[]) value);
} else if (value instanceof Iterable) {
this.printRecord((Iterable<?>) value);
} else {
this.printRecord(value);
}
}
printRecords(Arrays.asList(values));
}
/**
......
......@@ -38,8 +38,8 @@ import java.io.IOException;
*/
final class Lexer implements Closeable {
private static final String CR_STRING = Character.toString(Constants.