I am reading records from file and inserting into database.
I am using DB2 database.
The records is like:
abc pqr abcd
So before abc there are several spaces as well at the start of the record.
I am reading the file using SpringBatch program and inside field set mapper I am printing the string read from the file:
System.out.println("*" + fieldSet.readString("FULL_RECORD") + "*");
However, the result I am getting is:
*abc pqr abcd*
Which means that the leading spaces are not getting preserved.
The linetokenizer in my config file is:
<beans:property name="lineTokenizer">
<beans:bean class="org.springframework.batch.item.file.transform.FixedLengthTokenizer">
<beans:property name="columns" value="1-241"/>
<beans:property name="names" value="FULL_RECORD"/>
</beans:bean>
</beans:property>
I am using default line mapper class and passing above tokenizer as its property.
org.springframework.batch.item.file.mapping.DefaultLineMapper
How to preserve the leading spaces before each record?
take a look at the code
just change
too
see DefaultFieldSet.readRawString()