Hi Kevin,
I was using some terms loosely in my pervious post so things may not have been very clear. I'll make this post more specific by including code snippets.
I'm using Spring Batch and so I'm the reading is abstracted into org.beanio.spring.BeanIOFlatFileItemReader:
<bean id="genericBatchItemReader" class="org.beanio.spring.BeanIOFlatFileItemReader"
scope="step">
<property name="streamMapping" value="classpath:beanio-mapping.xml" />
<property name="streamName" value="myStream" />
<property name="resource"
value="/home/tmp/files/myfile.txt" />
</bean>
BeanIOFlatFileItemReader.doRead() uses BeanReader, which has the beanReader.getLineNumber() like you mentioned in your post. However, since this operation is abstracted out for me, I don't have a way to use line number.
I was considering extending BeanIOFlatFileItemReader, and overriding doRead(). That way I could still use the BeanIOFlatFileItemReader's doRead and add the line number after a line has been parsed. However, the instance of BeanReader seems to be private with no accessor methods. So, this may not work unless I implement my own version of BeanIOFlatFileItemReader.
Another alternative -- (seems like a stretch though), is there anyway to map line number via the mapping configuration?
As an aside, the one place I've had easy access to line-number information is when an error occurs and the control passes to a SkipListener:
<bean id="genericItemSkipListener" class="com.mypackage.GenericBatchItemSkipListener"
scope="step">
</bean>
public class GenericBatchItemSkipListener implements
SkipListener<MyBean, Throwable>, StepExecutionListener {
// ... other code
@Override
public void onSkipInRead(Throwable t) {
// ... other code
BeanReaderException beanReaderEx = (BeanReaderException) t;
int lineNum = beanReaderEx.getRecordContext().getLineNumber();
}
// ... other code
}
Thanks,
Niyant