You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Alpesh Kulkarni (JIRA)" <ji...@apache.org> on 2017/06/15 03:27:00 UTC
[jira] [Created] (CSV-211) CSVFormat.format trims last delimiter if
the delimiter is a white space
Alpesh Kulkarni created CSV-211:
-----------------------------------
Summary: CSVFormat.format trims last delimiter if the delimiter is a white space
Key: CSV-211
URL: https://issues.apache.org/jira/browse/CSV-211
Project: Commons CSV
Issue Type: Bug
Affects Versions: 1.4
Environment: Any.
Reporter: Alpesh Kulkarni
Priority: Minor
The function CSVFormat.format() trims off the last delimiter if the delimiter is a white space character and the value in the last column is null.
{code:java}
public String format(Object... values) {
StringWriter out = new StringWriter();
try {
(new CSVPrinter(out, this)).printRecord(values);
return out.toString().trim();
} catch (IOException var4) {
throw new IllegalStateException(var4);
}
}
{code}
For example, consider the following records (\t = tab)-
ID{color:red}\t{color}Name{color:red}\t{color}Country{color:red}\t{color}Age
1{color:red}\t{color}John Doe{color:red}\t{color}USA{color:red}\t{color}20
2{color:red}\t{color}Jane Doe{color:red}\t{color}USA{color:red}\t{color}
The CSVFormat.format() on both the rows returns the following -
ID{color:red}\t{color}Name{color:red}\t{color}Country{color:red}\t{color}Age
1{color:red}\t{color}John Doe{color:red}\t{color}USA{color:red}\t{color}20
2{color:red}\t{color}Jane Doe{color:red}\t{color}USA
Note that there is a missing delimiter for the last column in the second record.
This usually causes schema mismatch when we try and read back the CSV file as there is one less column in all the rows which have a null at the end.
I feel the trim() is unnecessary while returning *out.toString()*
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)