Commons CSV
  1. Commons CSV
  2. CSV-120

CSVFormat#withHeader doesn't work with CSVPrinter

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.0
    • Component/s: None
    • Labels:
      None

      Description

      In the current version CSVFormat#withHeader is only used by CSVParser. It would be nice if CSVPrinter also supported it. Ideally, the following line of code

      CSVPrinter csvPrinter
        = CSVFormat.TDF
          .withHeader("x")
          .print(Files.newBufferedWriter(Paths.get("data.csv")));
      csvPrinter.printRecord(42);
      csvPrinter.close();
      

      should produce

      x
      42
      

      If you're alright with the idea of automatically inserting headers, I can attach a patch.

        Activity

        Sergei Lebedev created issue -
        Gary Gregory made changes -
        Field Original Value New Value
        Summary 'withHeader' doesn't work for 'CSVPrinter' CSVFormat#withHeader doesn't work with CSVPrinter
        Hide
        Gary Gregory added a comment -

        Sounds like a good idea. Done:

        commit -m "<action issue="CSV-120" type="add" dev="ggregory" due-to="Sergei Lebedev">CSVFormat#withHeader doesn't work with CSVPrinter</action>" 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 1601517.
        
        Show
        Gary Gregory added a comment - Sounds like a good idea. Done: commit -m "<action issue="CSV-120" type="add" dev="ggregory" due-to="Sergei Lebedev">CSVFormat#withHeader doesn't work with CSVPrinter</action>" 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 1601517.
        Gary Gregory made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 1.0 [ 12320161 ]
        Resolution Fixed [ 1 ]
        Hide
        Sergei Lebedev added a comment -

        Thanks!

        Show
        Sergei Lebedev added a comment - Thanks!
        Benedikt Ritter made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        51m 10s 1 Gary Gregory 09/Jun/14 23:22
        Resolved Resolved Closed Closed
        65d 21h 44m 1 Benedikt Ritter 14/Aug/14 21:06

          People

          • Assignee:
            Unassigned
            Reporter:
            Sergei Lebedev
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development