Skip to content

Change default value of comment prefix in FlatFileItemReaderBuilder to be consistent with FlatFileItemReader #747

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
* 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 {
Expand All @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -134,7 +137,7 @@ public void setBufferedReaderFactory(BufferedReaderFactory bufferedReaderFactory

/**
* 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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -171,6 +172,7 @@ public FlatFileItemReaderBuilder<T> currentItemCount(int currentItemCount) {

/**
* 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.
Expand All @@ -183,7 +185,7 @@ public FlatFileItemReaderBuilder<T> addComment(String comment) {

/**
* An array of Strings that indicate lines that are comments (and therefore skipped by
* the reader.
* the reader). Defaults to {@link FlatFileItemReader#DEFAULT_COMMENT_PREFIXES}.
*
* @param comments an array of strings to identify comments.
* @return The current instance of the builder.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public void testCustomLineTokenizerFieldSetMapper() throws Exception {
public void testComments() throws Exception {
FlatFileItemReader<Foo> reader = new FlatFileItemReaderBuilder<Foo>()
.name("fooReader")
.resource(getResource("1,2,3\n@this is a comment\n+so is this\n4,5,6"))
.resource(getResource("1,2,3\n@this is a comment\n+so is this\n#so is this too\n4,5,6"))
.comments("@", "+")
.delimited()
.names("first", "second", "third")
Expand Down