Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FixedLength giving issues while trying to fetch only a subset of values

I do have a file which have many records or columns in a single row. This file is being used across multiple systems. Hence not all fields are required for my requirement. Hence if i set only a subset of values as shown below

<property name="lineTokenizer">
    <bean class="org.springframework.batch.item.file.transform.FixedLengthTokenizer">
        <property name="names" value="aa,cc,vv,bb" />
        <property name="columns" value="1-578,579-579,580-580,581-581" />
    </bean>
</property>

I get an exception as below

org.springframework.batch.item.file.transform.IncorrectLineLengthException: Line is shorter than max range 581
org.springframework.batch.item.file.transform.FixedLengthTokenizer.doTokenize(FixedLengthTokenizer.java:109)
org.springframework.batch.item.file.transform.AbstractLineTokenizer.tokenize(AbstractLineTokenizer.java:112)
org.springframework.batch.item.file.mapping.DefaultLineMapper.mapLine(DefaultLineMapper.java:43)
org.springframework.batch.item.file.FlatFileItemReader.doRead(FlatFileItemReader.java:180)

Do we have to do anything special to fetch only subset of values

like image 662
Kunchai Sodhom Avatar asked Dec 19 '25 09:12

Kunchai Sodhom


1 Answers

The exception is saying that the line is shorter than the range you're providing. As in, you're mapping too many columns, not too few.

That being said, you need to map the entire record in the FixedLengthTokenizer. However, the FieldSetMapper you use doesn't need to use all those fields.

like image 134
Michael Minella Avatar answered Dec 21 '25 07:12

Michael Minella



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!