if you know the count of fields per line you could use something like the AggregateItemRerader (from official Spring Batch Samples)
you do not need the header/footer concept, but rather something like a fieldCounter which decides when to set the resultHolder exhausted
[edith says]
I like the concept and created a running proof of concept example in my github repository, it's under "readers", look for "field-count-job.xml".
Only custom code used is:
Code:
/**
* FieldCountItemReader, constructs line by reading from wrapped reader, until
* field count is reached.
*/
public class FieldCountItemReader implements ItemReader<List<String>> {
private ItemReader<FieldSet> delegate;
private int count;
/** {@inheritDoc} */
@Override
public List<String> read() throws Exception {
List<String> fields = new ArrayList<String>();
FieldSet field = null;
// read until end of file
while ((field = delegate.read()) != null) {
String[] fieldSetValues = field.getValues();
for (int i = 0; i < fieldSetValues.length; i++) {
fields.add(field.getValues()[i]);
}
// field count reached ?
if (fields.size() != count) {
continue;
} else {
return fields;
}
}
// reader returned nothing
return null;
}
public void setCount(int count) {
this.count = count;
}
public void setDelegate(ItemReader<FieldSet> delegate) {
this.delegate = delegate;
}
}