It looks like this should never happen. But the javadoc for InputStream doesn't mention this explicitly. I guess this loop shouldn't harm. 

The only thing I'm afraid of is that this might cause busy waiting in some weird case when the underlying stream returns 0 instead of blocking for the next byte. But again, this shouldn't really happen in streaming apis, AFAIK.