I'm processing a binary stream and need to skip efficiently past a range of data that I'm not interested in, to some data that will be processed.
InputStream.skip(long)
doesn't make much in the way of guarantees:
Skips over and discards n bytes of data from this input stream. The skip method may, for a variety of reasons, end up skipping over some smaller number of bytes, possibly 0. This may result from any of a number of conditions; reaching end of file before n bytes have been skipped is only one possibility. The actual number of bytes skipped is returned.
I need to know that one of two things has happened:
- The stream ended
- The bytes were skipped
Simple enough. However, the leniency afforded in this description means that, for example, BufferedInputStream
can just skip a few bytes and return. Sure, it tells me that it's skipped just those few, but it's not clear why.
So my question is: can you make use of InputStream.skip(long)
in such a way as that you know when either the stream ends or the skip completes successfully?
InputStream
. Your extension looks interesting and I'll try it out shortly in the class where I need it. Currently my API tries to report whether the skip succeeded, so I may need to modify client code if no guarantee is possible. Thanks very much. – Wingard