As it is written, you have no guarantees, because mark() not required to report whether it was successful. To get a guarantee, you must first call markSupported () and it should return true .
Also, as indicated, the specified reading limit is very dangerous. If you use a stream that buffers in memory, it potentially allocates a 2 GB buffer. On the other hand, if you use FileInputStream , you're fine.
A better approach is to use a BufferedInputStream with an explicit buffer.
kdgregory
source share