I suppose you are working with record-based files.
Using a MultiResourceItemReader
(to read multiple files) with a FlatFileItemReader
(to parse file).
Our intention is to detect when a file reach the end so with a PeekableItemReader
we look-ahead for next record and if this is null
we meet the EOF
class EOFCheckItemReader<T> extends SingleItemPeekableItemReader<T> {
private int count;
T read() {
T item = super.read();
if(null == item) {
// EOF detected
manageEOF();
count = 0;
}
else {
count++;
}
return item;
}
private void manageEOF() {}
// Also implements update(), open(), close()
// to save count value into execution context
// No need to save delegate's state because we register it
// as stream into job's xml definition
}
Spring batch is heavly based on delegation so, using property "delegate" of MultiResourceItemReader
or SingleItemPeekableItemReader
we can solve easly the problem.
This is a simple skeleton (just an idea, I can't test it sorry):
<bean name="csvReader" class="FlatFileItemReader">
<!-- set all properties -->
</bean>
<bean name="eofCheckReader" class="EOFCheckItemReader">
<property name="delegate" ref="multiResourceReader" />
</bean>
<bean name="multiResourceReader">
<property name="resources" value="file://*.csv" />
<property name="delegate" ref="csvReader" />
</bean>
<step>
<chunk reader="eofCheckReader" />
<streams>
<stream ref="multiResourceReader" />
</streams>
</step>