Alex Rivera | Logout

Given a Java InputStream, how can I determine the current offset in the stream?

Asked 2008-10-27T15:24:55.403
17

I'd like something like a generic, re-usable getPosition() method that will tell me the number of bytes read from the starting point of the stream. Ideally, I would prefer this to work with all InputStreams, so that I don't have to wrap each and every one of them as I get them from disparate sources.

Does such a beast exist? If not, can anyone recommend an existing implementation of a counting InputStream?

Edit
Report

1 Answer

2

No. InputStream is intended to handle potentially infinite amounts of data, so a counter would get in the way. In addition to wrapping them all, you might be able to do something with aspects.

answered 2008-10-27T15:29:23.770

Your Answer