So, I'm feeding file data to an API that takes a Reader
, and I'd like a way to report progress.
It seems like it should be straightforward to write a FilterInputStream
implementation that wraps the FileInputStream
, keeps track of the number of bytes read vs. the total file size, and fires some event (or, calls some update()
method) to report fractional progress.
(Alternatively, it could report absolute bytes read, and somebody else could do the math -- maybe more generally useful in the case of other streaming situations.)
I know I've seen this before and I may even have done it before, but I can't find the code and I'm lazy. Has anyone got it laying around? Or can someone suggest a better approach?