diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/FlatFileItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/FlatFileItemReader.java index 047fa5bab..9e4e737bb 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/FlatFileItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/FlatFileItemReader.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2019 the original author or authors. + * Copyright 2006-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -61,7 +61,7 @@ public class FlatFileItemReader extends AbstractItemCountingItemStreamItemRea private int lineCount = 0; - private String[] comments = DEFAULT_COMMENT_PREFIXES; + protected String[] comments = DEFAULT_COMMENT_PREFIXES; private boolean noInput = false; @@ -229,7 +229,7 @@ public class FlatFileItemReader extends AbstractItemCountingItemStreamItemRea return line; } - private boolean isComment(String line) { + protected boolean isComment(String line) { for (String prefix : comments) { if (line.startsWith(prefix)) { return true; diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/FlatFileItemReaderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/FlatFileItemReaderTests.java index 32865878b..2d41364cc 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/FlatFileItemReaderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/FlatFileItemReaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2019 the original author or authors. + * Copyright 2008-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -215,6 +215,25 @@ public class FlatFileItemReaderTests { } + @Test + public void testCustomCommentDetectionLogic() throws Exception { + reader = new FlatFileItemReader() { + @Override + protected boolean isComment(String line) { + return super.isComment(line) || line.endsWith("2"); + } + }; + reader.setResource(getInputResource("#testLine1\ntestLine2\n//testLine3\ntestLine4\n")); + reader.setComments(new String[] {"#", "//"}); + reader.setLineMapper(new PassThroughLineMapper()); + reader.open(executionContext); + + assertEquals("testLine4", reader.read()); + assertNull(reader.read()); + + reader.close(); + } + @Test public void testRestartWithSkippedLines() throws Exception {