how to Configure spring-batch reader for fixed length formats Files (File Without any delimiter).
Each element is determined in relation to its starting and ending position.
Sample of line :
120180208FAILED
220180208SUCCES
120170208SUCCES
1 : code , 20180208 : date ,FAILED : status
you can use FixedLengthTokenizer reader for this.
This is how you can configure FixedLengthTokenizer
.
Sample Text file
UK21341EAH4121131.11customer1
UK21341EAH4221232.11customer2
UK21341EAH4321333.11customer3
UK21341EAH4421434.11customer4
UK21341EAH4521535.11customer5
Java Config
@Bean
public FixedLengthTokenizer fixedLengthTokenizer() {
FixedLengthTokenizer tokenizer = new FixedLengthTokenizer();
tokenizer.setNames("ISIN", "Quantity", "Price", "Customer");
tokenizer.setColumns(new Range(1,12),
new Range(13,15),
new Range(16,20),
new Range(21,29));
return tokenizer;
}
XML Config
<bean id="fixedLengthLineTokenizer"
class="org.springframework.batch.io.file.transform.FixedLengthTokenizer">
<property name="names" value="ISIN,Quantity,Price,Customer" />
<property name="columns" value="1-12, 13-15, 16-20, 21-29" />
</bean>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With