From ac69225cfc065ecbaed0f5ebb65798d481649fda Mon Sep 17 00:00:00 2001 From: Vincent Boulaye Date: Mon, 7 Oct 2019 08:24:49 +0200 Subject: [PATCH] fixes #15 back to SKIP_EMPTY_LINES --- .../fasterxml/jackson/dataformat/csv/CsvParser.java | 4 +++- .../jackson/dataformat/csv/impl/CsvDecoder.java | 8 +++++++- .../dataformat/csv/deser/SkipBlankLines15Test.java | 12 ++++++------ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/csv/src/main/java/com/fasterxml/jackson/dataformat/csv/CsvParser.java b/csv/src/main/java/com/fasterxml/jackson/dataformat/csv/CsvParser.java index 6a6d2de9..5f371ff5 100644 --- a/csv/src/main/java/com/fasterxml/jackson/dataformat/csv/CsvParser.java +++ b/csv/src/main/java/com/fasterxml/jackson/dataformat/csv/CsvParser.java @@ -78,8 +78,10 @@ public enum Feature * depending on binding, `null`). *

* Feature is disabled by default. + * + * @since 2.10 */ - SKIP_BLANK_LINES(false), + SKIP_EMPTY_LINES(false), /** * Feature that allows there to be a trailing single extraneous data diff --git a/csv/src/main/java/com/fasterxml/jackson/dataformat/csv/impl/CsvDecoder.java b/csv/src/main/java/com/fasterxml/jackson/dataformat/csv/impl/CsvDecoder.java index ae319e45..3ca4cf8f 100644 --- a/csv/src/main/java/com/fasterxml/jackson/dataformat/csv/impl/CsvDecoder.java +++ b/csv/src/main/java/com/fasterxml/jackson/dataformat/csv/impl/CsvDecoder.java @@ -269,7 +269,7 @@ public CsvDecoder(IOContext ctxt, CsvParser owner, Reader r, _textBuffer = textBuffer; _autoCloseInput = StreamReadFeature.AUTO_CLOSE_SOURCE.enabledIn(stdFeatures); _allowComments = CsvParser.Feature.ALLOW_COMMENTS.enabledIn(csvFeatures); - _skipBlankLines = CsvParser.Feature.SKIP_BLANK_LINES.enabledIn(csvFeatures); + _skipBlankLines = CsvParser.Feature.SKIP_EMPTY_LINES.enabledIn(csvFeatures); _trimSpaces = CsvParser.Feature.TRIM_SPACES.enabledIn(csvFeatures); _inputBuffer = ctxt.allocTokenBuffer(); _bufferRecyclable = true; // since we allocated it @@ -478,6 +478,12 @@ public boolean startNewLine() throws IOException { return skipLinesWhenNeeded(); } + /** + * optionally skip lines that are empty or are comments, depending on the feature activated in the parser + * @return false if the end of input was reached + * @throws IOException + * @since 2.10 + */ public boolean skipLinesWhenNeeded() throws IOException { if (!(_allowComments || _skipBlankLines)) { return hasMoreInput(); diff --git a/csv/src/test/java/com/fasterxml/jackson/dataformat/csv/deser/SkipBlankLines15Test.java b/csv/src/test/java/com/fasterxml/jackson/dataformat/csv/deser/SkipBlankLines15Test.java index aa5608c2..7e8de0fe 100644 --- a/csv/src/test/java/com/fasterxml/jackson/dataformat/csv/deser/SkipBlankLines15Test.java +++ b/csv/src/test/java/com/fasterxml/jackson/dataformat/csv/deser/SkipBlankLines15Test.java @@ -27,7 +27,7 @@ public void testCsvWithEmptyLineSkipBlankLinesFeatureDisabled() throws Exception public void testCsvWithEmptyLineSkipBlankLinesFeatureEnabled() throws Exception { String[][] rows = mapperForCsvAsArray() - .with(CsvParser.Feature.SKIP_BLANK_LINES) + .with(CsvParser.Feature.SKIP_EMPTY_LINES) .readValue(CSV_WITH_EMPTY_LINE); // empty line is skipped assertArrayEquals(expected( @@ -50,7 +50,7 @@ public void testCsvWithBlankLineSkipBlankLinesFeatureDisabled() throws Exception public void testCsvWithBlankLineSkipBlankLinesFeatureEnabled() throws Exception { String[][] rows = mapperForCsvAsArray() - .with(CsvParser.Feature.SKIP_BLANK_LINES) + .with(CsvParser.Feature.SKIP_EMPTY_LINES) .readValue(CSV_WITH_BLANK_LINE); // blank line is skipped assertArrayEquals(expected( @@ -74,7 +74,7 @@ public void testCsvWithBlankLineAndCommentSkipBlankLinesFeatureDisabled() throws public void testCsvWithBlankLineAndCommentSkipBlankLinesFeatureEnabled() throws Exception { String[][] rows = mapperForCsvAsArray() - .with(CsvParser.Feature.SKIP_BLANK_LINES) + .with(CsvParser.Feature.SKIP_EMPTY_LINES) .readValue(CSV_WITH_BLANK_LINE_AND_COMMENT); // blank/empty lines are skipped assertArrayEquals(expected( @@ -86,7 +86,7 @@ public void testCsvWithBlankLineAndCommentSkipBlankLinesFeatureEnabled() throws public void testCsvWithBlankLineAndCommentSkipBlankLinesFeatureEnabledAndAllowComments() throws Exception { String[][] rows = mapperForCsvAsArray() - .with(CsvParser.Feature.SKIP_BLANK_LINES) + .with(CsvParser.Feature.SKIP_EMPTY_LINES) .with(CsvParser.Feature.ALLOW_COMMENTS) .readValue(CSV_WITH_BLANK_LINE_AND_COMMENT); // blank/empty/comment lines are skipped @@ -109,7 +109,7 @@ public void testCsvWithFirstBlankLineSkipBlankLinesFeatureDisabled() throws Exce public void testCsvWithFirstBlankLineSkipBlankLinesFeatureEnabled() throws Exception { String[][] rows = mapperForCsvAsArray() - .with(CsvParser.Feature.SKIP_BLANK_LINES) + .with(CsvParser.Feature.SKIP_EMPTY_LINES) .readValue(CSV_WITH_FIRST_BLANK_LINE); // blank line is skipped assertArrayEquals(expected( @@ -133,7 +133,7 @@ public void testCsvWithTrailingBlankLineSkipBlankLinesFeatureDisabled() throws E public void testCsvWithTrailingBlankLineSkipBlankLinesFeatureEnabled() throws Exception { String[][] rows = mapperForCsvAsArray() - .with(CsvParser.Feature.SKIP_BLANK_LINES) + .with(CsvParser.Feature.SKIP_EMPTY_LINES) .readValue(CSV_WITH_FIRST_BLANK_LINE); // blank lines are skipped assertArrayEquals(expected(