Skip to content

Commit 65f110e

Browse files
committed
<action issue="CSV-119" type="add" dev="ggregory" due-to="Sergei Lebedev">CSVFormat is missing a print(...) method</action>
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1599285 13f79535-47bb-0310-9956-ffa450edef68
1 parent 2480dff commit 65f110e

3 files changed

Lines changed: 25 additions & 0 deletions

File tree

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
<body>
4141

4242
<release version="1.0" date="TBD" description="First release">
43+
<action issue="CSV-119" type="add" dev="ggregory" due-to="Sergei Lebedev">CSVFormat is missing a print(...) method</action>
4344
<action issue="CSV-118" type="fix" dev="ggregory" due-to="Enrique Lara">CSVRecord.toMap() throws NPE on formats with no
4445
headers.</action>
4546
<action issue="CSV-113" type="fix" dev="sebb">Check whether ISE/IAE are being used appropriately</action>

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,21 @@ public CSVParser parse(final Reader in) throws IOException {
595595
return new CSVParser(in, this);
596596
}
597597

598+
/**
599+
* Prints to the specified output.
600+
*
601+
* <p>
602+
* See also {@link CSVPrinter}.
603+
* </p>
604+
*
605+
* @param out
606+
* the output
607+
* @return a printer to an output
608+
*/
609+
public CSVPrinter print(final Appendable out) {
610+
return new CSVPrinter(out, this);
611+
}
612+
598613
@Override
599614
public String toString() {
600615
final StringBuilder sb = new StringBuilder();

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,15 @@ public void testPrinter7() throws IOException {
303303
printer.close();
304304
}
305305

306+
@Test
307+
public void testPrint() throws IOException {
308+
final StringWriter sw = new StringWriter();
309+
final CSVPrinter printer = CSVFormat.DEFAULT.print(sw);
310+
printer.printRecord("a", "b\\c");
311+
assertEquals("a,b\\c" + recordSeparator, sw.toString());
312+
printer.close();
313+
}
314+
306315
@Test
307316
public void testPrintNullValues() throws IOException {
308317
final StringWriter sw = new StringWriter();

0 commit comments

Comments
 (0)