Description
Raja Rajan R S opened BATCH-1868 and commented
When it is required to create output files with MultiResourceItemWriter with all files having the exact line count as mentioned in the itemCountLimitPerResource attribute, Spring batch creates files with varying line counts (varying between the itemCountLimitPerResource value and commit-interval value). The attached class FixedLinesMultiResourceItemWriter.java creates the multiple files with every file having exactly same no of lines as defined by itemCountLimitPerResource attribute.
The usage of the class in the configuration should be as given below.
<beans:bean id="fixedLineCountWriter" class="org.springframework.batch.item.file.FixedLinesMultiResourceItemWriter" scope="step">
<beans:property name="name" value="fw1" />
<beans:property name="resource"
value="file:#{jobParameters['output.file.path.first']}" />
<beans:property name="resourceSuffixCreator" ref="suffixCreator" />
<beans:property name="saveState" value="true" />
<beans:property name="itemCountLimitPerResource" value="250000" />
<beans:property name="fields" value="comma,seperated,field,names,as,in,the,POJO,class" />
<beans:property name="delimitter" value=""|"" />
</beans:bean>
where the value for the property fields should be the comma seperate list of field names to be printed in the output file. Field names should always match the name of the attributesas declared in the POJO class definition. Say for example for a Customer Name bean class the value of "fields" property can be "firstName,LastName,MiddleName,title" if these attributes are declared in the bean class.
This has been tested in our spring batch application and confirmed working fine.
Affects: 2.1.8
Attachments:
- FixedLinesMultiResourceItemWriter.java (6.83 kB)