An InputStream is by definition not searchable. You can only skip forward, not backward in the stream (the only exception is to rewind the stream with reset (), it only works in threads that support the label).
As for the skip () method, skipping is always possible, because the InputStream class already implements it in the general case by simply reading and discarding bytes. A separate subclass of InputStream can implement it in different ways (more efficient for a particular type).
Throw comment: "IOException - if the stream does not support the search, or some other I / O error occurs." It is misleading because it implies that there may be streams that categorically do not allow bytes to be skipped (which does not make sense, since skips are semantically the same as read + discard).
source share