Skip to content

Commit 9dde586

Browse files
committed
Open FlatFileItemReader#isComment for extension
Resolves #1134
1 parent 67317e6 commit 9dde586

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/FlatFileItemReader.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2019 the original author or authors.
2+
* Copyright 2006-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -61,7 +61,7 @@ public class FlatFileItemReader<T> extends AbstractItemCountingItemStreamItemRea
6161

6262
private int lineCount = 0;
6363

64-
private String[] comments = DEFAULT_COMMENT_PREFIXES;
64+
protected String[] comments = DEFAULT_COMMENT_PREFIXES;
6565

6666
private boolean noInput = false;
6767

@@ -229,7 +229,7 @@ private String readLine() {
229229
return line;
230230
}
231231

232-
private boolean isComment(String line) {
232+
protected boolean isComment(String line) {
233233
for (String prefix : comments) {
234234
if (line.startsWith(prefix)) {
235235
return true;

spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/FlatFileItemReaderTests.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2008-2019 the original author or authors.
2+
* Copyright 2008-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -215,6 +215,25 @@ public String preProcess(String record) {
215215

216216
}
217217

218+
@Test
219+
public void testCustomCommentDetectionLogic() throws Exception {
220+
reader = new FlatFileItemReader<String>() {
221+
@Override
222+
protected boolean isComment(String line) {
223+
return super.isComment(line) || line.endsWith("2");
224+
}
225+
};
226+
reader.setResource(getInputResource("#testLine1\ntestLine2\n//testLine3\ntestLine4\n"));
227+
reader.setComments(new String[] {"#", "//"});
228+
reader.setLineMapper(new PassThroughLineMapper());
229+
reader.open(executionContext);
230+
231+
assertEquals("testLine4", reader.read());
232+
assertNull(reader.read());
233+
234+
reader.close();
235+
}
236+
218237
@Test
219238
public void testRestartWithSkippedLines() throws Exception {
220239

0 commit comments

Comments
 (0)