Results 1 to 6 of 6

Thread: File read count

  1. #1
    Join Date
    Feb 2011
    Posts
    3

    Default 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?

  2. #2

    Default

    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).

  3. #3
    Join Date
    Feb 2011
    Posts
    3

    Default

    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.

  4. #4

    Default

    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)

  5. #5
    Join Date
    Feb 2011
    Posts
    3

    Default

    What way did you do you file read count within the before step. As I have come across an AbstractItemCountingItemStreamItemReader, did you use this?

  6. #6

    Default

    Quote Originally Posted by madphooka View Post
    What way did you do you file read count within the before step. As I have come across an AbstractItemCountingItemStreamItemReader, did you use this?
    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.

    Just count the number of items in beforeStep and put them in your execution context.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •