Unterminated Double Quotes in Spring Batch

前端 未结 2 570
广开言路
广开言路 2020-12-19 22:10

I am new to Spring Batch and I have run into a problem.

The batch application I am working on reads and processes lines from a delimited text file. I have configure

2条回答
  •  天涯浪人
    2020-12-19 22:59

    I ran into the same problem. However the proposed solution is not an optimal one. What if in your data there isn't a suitable quote character? Unfortunately we don't always have control over input data and pre-processing them is not often a good idea. Exploring the DelimitedLineTokenizer source code I decided to adopt this solution that I will share with this answer. It requires to override a class, but with this we totally remove the quote character issue.

    import org.springframework.batch.item.file.transform.DelimitedLineTokenizer;
    
        public class CustomDelimitedLineTokenizer extends DelimitedLineTokenizer {
    
            @Override
            protected boolean isQuoteCharacter(char c) {
                return false;
            }
    
        } 
    

    This way the DelimitedLineTokenizer can't recognize the quote character. Of course if we need this functionality then this solution is not adoptable, however I think it is better than the proposed one that just sort the issue instead of solving it. Hope it will help someone.

提交回复
热议问题