[
https://issues.apache.org/jira/browse/CSV-130?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Gary Gregory resolved CSV-130.
------------------------------
Resolution: Fixed
Fix Version/s: 1.1
Please review the code in trunk.
{noformat}
commit -m "[CSV-130] CSVFormat#withHeader doesn't work well with #printComment,
add withHeaderComments(String...)"
C:/vcs/svn/apache/commons/trunks-proper/csv/src/main/java/org/apache/commons/csv/CSVFormat.java
C:/vcs/svn/apache/commons/trunks-proper/csv/src/main/java/org/apache/commons/csv/CSVPrinter.java
C:/vcs/svn/apache/commons/trunks-proper/csv/src/test/java/org/apache/commons/csv/CSVPrinterTest.java
C:/vcs/svn/apache/commons/trunks-proper/csv/src/changes/changes.xml
Sending
C:/vcs/svn/apache/commons/trunks-proper/csv/src/changes/changes.xml
Sending
C:/vcs/svn/apache/commons/trunks-proper/csv/src/main/java/org/apache/commons/csv/CSVFormat.java
Sending
C:/vcs/svn/apache/commons/trunks-proper/csv/src/main/java/org/apache/commons/csv/CSVPrinter.java
Sending
C:/vcs/svn/apache/commons/trunks-proper/csv/src/test/java/org/apache/commons/csv/CSVPrinterTest.java
Transmitting file data ...
Committed revision 1623984.
{noformat}
> CSVFormat#withHeader doesn't work well with #printComment, add
> withHeaderComments(String...)
> --------------------------------------------------------------------------------------------
>
> Key: CSV-130
> URL: https://issues.apache.org/jira/browse/CSV-130
> Project: Commons CSV
> Issue Type: Improvement
> Components: Printer
> Affects Versions: 1.0
> Reporter: Sergei Lebedev
> Priority: Minor
> Fix For: 1.1
>
>
> For some applications it might be useful to add a top comment to the CSV file
> being printed. However, this isn't possible with #120 implemented the way it
> is. Here's an example:
> {code}
> public class Example {
> public static void main(final String[] args) throws IOException {
> final CSVPrinter csvPrinter = CSVFormat.TDF
> .withCommentMarker('#')
> .withHeader("foo", "bar")
> .print(System.out);
> csvPrinter.printComment("generated by yada v1.0");
> csvPrinter.printComment("foo some description");
> csvPrinter.printComment("bar more here");
> csvPrinter.printRecord(42, 24);
> csvPrinter.printRecord(24, 42);
> }
> }
> // Outputs:
> // foo bar
> // # generated by yada v1.0
> // # foo some description
> // # bar more here
> // 42 24
> // 24 42
> {code}
> Obviously, there's a way to "fix" this: output the header in the first call
> to `#printRecord`, but it just doesn't feel right. What to do you think?
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)