Skip to content

FlatFileItemReaderBuilder class - TAB character is not set as a delimiter [BATCH-2738] #866

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
spring-projects-issues opened this issue Jul 8, 2018 · 0 comments
Labels
has: backports Legacy label from JIRA. Superseded by "for: backport-to-x.x.x" in: core type: bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Valentin CHIVU opened BATCH-2738 and commented

Hi Spring Batch Team,

My name is Valentin, I am from Romania, I am Java Application Developer and I work for a project by using Spring Batch Core framework.
My project requires to create a batch which reads data from a simple flat file with TAB character as a field separator.

I use your new feature Spring Batch Core 4 class org.springframework.batch.item.file.builder.FlatFileItemReaderBuilder.DelimitedBuilder. In my code, I want to set the TAB delimiter by the next sequence:

FlatFileItemReaderBuilder<MyData> flatFileItemReaderBuilder = new FlatFileItemReaderBuilder<>();
FlatFileItemReaderBuilder.DelimitedBuilder<MyData> flatFileItemReaderBuilderDelimited = flatFileItemReaderBuilder.delimited();
flatFileItemReaderBuilderDelimited.delimiter(DelimitedLineTokenizer.DELIMITER_TAB);
// flatFileItemReaderBuilderDelimited.delimiter("\t");

I've found +the TAB character is not set as a delimiter+ on the field org.springframework.batch.item.file.builder.FlatFileItemReaderBuilder.DelimitedBuilder.delimiter. I've found that, in general, the delimiter is set by the method org.springframework.batch.item.file.builder.FlatFileItemReaderBuilder.DelimitedBuilder.build() at line 631, by the sequence:
 
if(StringUtils.hasText(this.delimiter)) {
                tokenizer.setDelimiter(this.delimiter);
}

Here the delimiter is checked against the method org.springframework.util.StringUtils.hasText(String). According to the hasText() method specification, "this method returns true if the String is not null, its length is greater than 0, and it contains at least one non-whitespace character." But in the case of TAB character, the string contains only one character (i.e. TAB character) which is a whitespace character, thus the condition is not valid, and the TAB character is not set as a delimiter.

Please correct me if I am wrong. As long as DelimitedLineTokenizer.DELIMITER_TAB constant exists, to exclude the TAB character was not an intention, and maybe this is a bug. 
 
I think the class FlatFileItemReaderBuilder is a very good idea. I have already used this class for other separators. I am looking forward to your feedback.

P.S. For the moment, I have solved the problem by using the classic Spring Batch 3 style.

Best Regards,
Valentin CHIVU
Java Developer
Romania


Affects: 4.0.1

Reference URL: https://stackoverflow.com/questions/51738718/flatfileitemreader-tab-delimiter-not-working

Referenced from: pull request #626, and commits b11d49a, 80d1a24

Backported to: 4.1.0.M3, 4.0.2

@spring-projects-issues spring-projects-issues added type: bug has: backports Legacy label from JIRA. Superseded by "for: backport-to-x.x.x" in: core labels Dec 16, 2019
@spring-projects-issues spring-projects-issues added this to the 4.1.0 milestone Dec 16, 2019
This was referenced Dec 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has: backports Legacy label from JIRA. Superseded by "for: backport-to-x.x.x" in: core type: bug
Projects
None yet
Development

No branches or pull requests

1 participant