|
30 | 30 | import java.io.File; |
31 | 31 | import java.io.IOException; |
32 | 32 | import java.io.PrintStream; |
| 33 | +import java.io.Reader; |
33 | 34 | import java.io.StringReader; |
34 | 35 | import java.io.StringWriter; |
35 | 36 | import java.io.Writer; |
@@ -1471,4 +1472,31 @@ private String[] toFirstRecordValues(final String expected, final CSVFormat form |
1471 | 1472 | return CSVParser.parse(expected, format).getRecords().get(0).values(); |
1472 | 1473 | } |
1473 | 1474 |
|
| 1475 | + @Test |
| 1476 | + public void testPrintReaderWithoutQuoteToWriter() throws IOException { |
| 1477 | + // Test to target the use of IOUtils::copyLarge. |
| 1478 | + // Requires the format to have no quote or escape character, |
| 1479 | + // value to be a java.io.Reader and the output to be a java.io.Writer. |
| 1480 | + final StringWriter sw = new StringWriter(); |
| 1481 | + final String content = "testValue"; |
| 1482 | + try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(null))) { |
| 1483 | + final StringReader value = new StringReader(content); |
| 1484 | + printer.print(value); |
| 1485 | + } |
| 1486 | + assertEquals(content, sw.toString()); |
| 1487 | + } |
| 1488 | + |
| 1489 | + @Test |
| 1490 | + public void testPrintReaderWithoutQuoteToAppendable() throws IOException { |
| 1491 | + // Test to target the use of IOUtils::copy. |
| 1492 | + // Requires the format to have no quote or escape character, |
| 1493 | + // value to be a java.io.Reader and the output to not be a java.io.Writer. |
| 1494 | + final StringBuilder sb = new StringBuilder(); |
| 1495 | + final String content = "testValue"; |
| 1496 | + try (final CSVPrinter printer = new CSVPrinter(sb, CSVFormat.DEFAULT.withQuote(null))) { |
| 1497 | + final StringReader value = new StringReader(content); |
| 1498 | + printer.print(value); |
| 1499 | + } |
| 1500 | + assertEquals(content, sb.toString()); |
| 1501 | + } |
1474 | 1502 | } |
0 commit comments