Fix default value of comment prefix in FlatFileItemReaderBuilder

Before this commit, the default value of comment prefix in
FlatFileItemReaderBuilder was not consistent with the one in
FlatFileItemReader.

This commit changes the default value of comment prefix to # in
the builder to be consistent with the reader.

Resolves BATCH-2862
This commit is contained in:
Mahmoud Ben Hassine
2019-11-28 15:08:34 +01:00
parent e5855c7e6b
commit 38b43e8aaf
3 changed files with 13 additions and 7 deletions

View File

@@ -41,6 +41,7 @@ import org.springframework.util.StringUtils;
* about the problematic line and its line number.
*
* @author Robert Kasanicky
* @author Mahmoud Ben Hassine
*/
public class FlatFileItemReader<T> extends AbstractItemCountingItemStreamItemReader<T> implements
ResourceAwareItemReaderItemStream<T>, InitializingBean {
@@ -50,6 +51,8 @@ public class FlatFileItemReader<T> extends AbstractItemCountingItemStreamItemRea
// default encoding for input files
public static final String DEFAULT_CHARSET = Charset.defaultCharset().name();
public static final String[] DEFAULT_COMMENT_PREFIXES = new String[] { "#" };
private RecordSeparatorPolicy recordSeparatorPolicy = new SimpleRecordSeparatorPolicy();
private Resource resource;
@@ -58,7 +61,7 @@ public class FlatFileItemReader<T> extends AbstractItemCountingItemStreamItemRea
private int lineCount = 0;
private String[] comments = new String[] { "#" };
private String[] comments = DEFAULT_COMMENT_PREFIXES;
private boolean noInput = false;
@@ -134,7 +137,7 @@ public class FlatFileItemReader<T> extends AbstractItemCountingItemStreamItemRea
/**
* Setter for comment prefixes. Can be used to ignore header lines as well by using e.g. the first couple of column
* names as a prefix.
* names as a prefix. Defaults to {@link #DEFAULT_COMMENT_PREFIXES}.
*
* @param comments an array of comment line prefixes.
*/

View File

@@ -76,7 +76,8 @@ public class FlatFileItemReaderBuilder<T> {
private Resource resource;
private List<String> comments = new ArrayList<>();
private List<String> comments =
new ArrayList<>(Arrays.asList(FlatFileItemReader.DEFAULT_COMMENT_PREFIXES));
private int linesToSkip = 0;
@@ -171,6 +172,7 @@ public class FlatFileItemReaderBuilder<T> {
/**
* Add a string to the list of Strings that indicate commented lines.
* Defaults to {@link FlatFileItemReader#DEFAULT_COMMENT_PREFIXES}.
*
* @param comment the string to define a commented line.
* @return The current instance of the builder.
@@ -182,15 +184,16 @@ public class FlatFileItemReaderBuilder<T> {
}
/**
* An array of Strings that indicate lines that are comments (and therefore skipped by
* the reader.
* Set an array of Strings that indicate lines that are comments (and therefore skipped by
* the reader). This method overrides the default comment prefixes which are
* {@link FlatFileItemReader#DEFAULT_COMMENT_PREFIXES}.
*
* @param comments an array of strings to identify comments.
* @return The current instance of the builder.
* @see FlatFileItemReader#setComments(String[])
*/
public FlatFileItemReaderBuilder<T> comments(String... comments) {
this.comments.addAll(Arrays.asList(comments));
this.comments = Arrays.asList(comments);
return this;
}