In my logger code, I am using FileInputStream for reading the log files. The number of bytes in the file that were last read from the log file ‘byteOffset’ is stored. Whenever the reader has to read the log it would do FileInputStream.skip(byteOffset) and reads from there. In this context, I found the statement below from the InputStream.skip() documentation.
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.
Apart from what is mentioned in the documentation, for what other reasons will the actual skipped data vary from the input? I just want to be sure what all cases I need to be prepared for in my log reader code.
It depends on the implementation. Maybe it’s a buffered stream, and it only has 100 bytes read from the backing stream, and retrieving more more bytes would take more time.
(I don’t think that was a good decision to put that part in the
InputStreamspecification, but it’s impossible to change now.)