Feb 2nd, 2011, 01:26 PM
File read count
I am having difficulty in trying to obtain a file read count within itemprocessor.
I have read similiar posts that are related to file read counter and they all suggest obtaining the readCount within the stepexecutionlistener afterStep, this approach is not suitable as I need the readCount total within the current step, not when the step has finished.
The purpose of trying to obtain readCount value within itemprocessor is that I am calculating the batch progress in which I pass back the value to the gui along with a number of other totals which are used for reporting purposes.
I have tried extending itemStream within ItemProcessor and using the open method try obtain readCount within executionContext by searching for read.count key but I get an null pointer exception.
Could anyone please put me in the right direction of obtaing a file readcount within itemprocessor?
Feb 3rd, 2011, 02:23 AM
What do you want exactly? The total number of items in your file or the item number that your file is currently reading?
You will never get the total number of items in your processor because, by default, the reader does not know it. If you really want to do this, you need to compute that by scanning the whole file first before starting the step (beforeStep callback might suit that).
Feb 3rd, 2011, 03:04 AM
Thank you for replying, I wanted to get the total number of lines read in a file.
In the before step I can count the total number of lines read in a file and then put this variable in the executionstepcontext, ok i'll try that.
Feb 3rd, 2011, 03:11 AM
That's what we did and it's working fine as long as the delimiter between two items are not too complicated (one line = one item is ideal of course)
Feb 3rd, 2011, 03:22 AM
What way did you do you file read count within the before step. As I have come across an AbstractItemCountingItemStreamItemReader, did you use this?
Feb 3rd, 2011, 03:29 AM
No. How about reading the Javadoc of that class before asking the question. It clearly states it's counting the elements in order to be able to restart on the last one in case of failure.
Originally Posted by madphooka
Just count the number of items in beforeStep and put them in your execution context.