|
31 | 31 | import java.io.File; |
32 | 32 | import java.io.IOException; |
33 | 33 | import java.io.InputStreamReader; |
| 34 | +import java.io.PipedReader; |
| 35 | +import java.io.PipedWriter; |
34 | 36 | import java.io.Reader; |
35 | 37 | import java.io.StringReader; |
36 | 38 | import java.io.StringWriter; |
@@ -69,6 +71,8 @@ public class CSVParserTest { |
69 | 71 |
|
70 | 72 | private static final String CSV_INPUT_1 = "a,b,c,d"; |
71 | 73 |
|
| 74 | + private static final String CSV_INPUT_2 = "a,b,1 2"; |
| 75 | + |
72 | 76 | private static final String[][] RESULT = { |
73 | 77 | {"a", "b", "c", "d"}, |
74 | 78 | {"a", "b", "1 2"}, |
@@ -530,6 +534,29 @@ public void testGetOneLineCustomCollection() throws IOException { |
530 | 534 | parser.close(); |
531 | 535 | } |
532 | 536 |
|
| 537 | + /** |
| 538 | + * Tests reusing a parser to process new string records one at a time as they are being discovered. See [CSV-110]. |
| 539 | + * |
| 540 | + * @throws IOException |
| 541 | + */ |
| 542 | + @Test |
| 543 | + public void testGetOneLineOneParser() throws IOException { |
| 544 | + PipedWriter writer = new PipedWriter(); |
| 545 | + PipedReader reader = new PipedReader(writer); |
| 546 | + final CSVFormat format = CSVFormat.DEFAULT; |
| 547 | + final CSVParser parser = new CSVParser(reader, format); |
| 548 | + try { |
| 549 | + writer.append(CSV_INPUT_1 + format.getRecordSeparator()); |
| 550 | + final CSVRecord record1 = parser.nextRecord(); |
| 551 | + assertArrayEquals(RESULT[0], record1.values()); |
| 552 | + writer.append(CSV_INPUT_2 + format.getRecordSeparator()); |
| 553 | + final CSVRecord record2 = parser.nextRecord(); |
| 554 | + assertArrayEquals(RESULT[1], record2.values()); |
| 555 | + } finally { |
| 556 | + parser.close(); |
| 557 | + } |
| 558 | + } |
| 559 | + |
533 | 560 | @Test |
534 | 561 | public void testGetRecordNumberWithCR() throws Exception { |
535 | 562 | this.validateRecordNumbers(String.valueOf(CR)); |
|
0 commit comments