When does InputStream.skip () miss less expected bytes?

In my boolean code, I use FileInputStream to read log files. The number of bytes in the file that was last read from the "byteOffset" log file is saved. Whenever a reader needs to read a magazine, it will do FileInputStream.skip(byteOffset) and read from there. In this context, I found the expression below from the InputStream.skip() documentation.

Skips and removes n bytes of data from this input stream. The skipping method may, for various reasons, result in skipping some fewer bytes , possibly 0. This may be the result of any of a number of conditions; until the end of the file, up to n bytes, only one possibility is missed.

Besides what is indicated in the documentation, for what other reasons can the actual missing data differ from the input? I just want to make sure that all the cases in which I have to be prepared in the code for reading the magazine.

+4
source share
1 answer

It depends on the implementation. Perhaps this is a buffered stream, and it only has 100 bytes read from the support stream, and it takes more time to get more bytes.

(I don’t think it was the right decision to include this part in the InputStream specification, but now it’s impossible to change it.)

+2
source

Source: https://habr.com/ru/post/1436706/


All Articles