Repository: commons-csv Updated Branches: refs/heads/master 0e3b57507 -> 2305e0e80
[CSV-213] CSVParser#iterator()#hasNext() fails. Project: http://git-wip-us.apache.org/repos/asf/commons-csv/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-csv/commit/2305e0e8 Tree: http://git-wip-us.apache.org/repos/asf/commons-csv/tree/2305e0e8 Diff: http://git-wip-us.apache.org/repos/asf/commons-csv/diff/2305e0e8 Branch: refs/heads/master Commit: 2305e0e80c9ceaba6736bea4dbf07c0979279280 Parents: 0e3b575 Author: Gary Gregory <[email protected]> Authored: Thu Jul 20 21:10:09 2017 -0700 Committer: Gary Gregory <[email protected]> Committed: Thu Jul 20 21:10:09 2017 -0700 ---------------------------------------------------------------------- .../commons/csv/issues/JiraCsv213Test.java | 58 ++++++++++++++++++++ src/test/resources/CSV-213/999751170.patch.csv | 2 + 2 files changed, 60 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-csv/blob/2305e0e8/src/test/java/org/apache/commons/csv/issues/JiraCsv213Test.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv213Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv213Test.java new file mode 100644 index 0000000..c367dd7 --- /dev/null +++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv213Test.java @@ -0,0 +1,58 @@ +package org.apache.commons.csv.issues; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; + +import org.apache.commons.csv.CSVFormat; +import org.apache.commons.csv.CSVParser; +import org.apache.commons.csv.CSVRecord; +import org.apache.commons.csv.QuoteMode; +import org.junit.Ignore; +import org.junit.Test; + +/** + * Tests https://issues.apache.org/jira/browse/CSV-213 + * + * This is normal behavior with the current architecture: The iterator() API presents an object that is backed by data + * in the CSVParser as the parser is streaming over the file. The CSVParser is like a forward-only stream. When you + * create a new Iterator you are only created a new view on the same position in the parser's stream. For the behavior + * you want, you need to open a new CSVParser. + * + */ +@Ignore +public class JiraCsv213Test { + + private void createEndChannel(File csvFile) { + // @formatter:off + final CSVFormat csvFormat = + CSVFormat.DEFAULT + .withDelimiter(';') + .withFirstRecordAsHeader() + .withRecordSeparator('\n') + .withQuoteMode(QuoteMode.ALL); + // @formatter:on + try (CSVParser parser = csvFormat + .parse(new InputStreamReader(new FileInputStream(csvFile), StandardCharsets.UTF_8))) { + if (parser.iterator().hasNext()) { + System.out.println(parser.getCurrentLineNumber()); + System.out.println(parser.getRecordNumber()); + // get only first record we don't need other's + CSVRecord firstRecord = parser.iterator().next(); // this fails + + return; + } + } catch (IOException e) { + throw new RuntimeException("Error while adding end channel to csv", e); + } + + return; + } + + @Test + public void test() { + createEndChannel(new File("src/test/resources/CSV-213/999751170.patch.csv")); + } +} http://git-wip-us.apache.org/repos/asf/commons-csv/blob/2305e0e8/src/test/resources/CSV-213/999751170.patch.csv ---------------------------------------------------------------------- diff --git a/src/test/resources/CSV-213/999751170.patch.csv b/src/test/resources/CSV-213/999751170.patch.csv new file mode 100644 index 0000000..42a9d1f --- /dev/null +++ b/src/test/resources/CSV-213/999751170.patch.csv @@ -0,0 +1,2 @@ +"CHANELID";"ADDRESS" +"27";""
