A stream might fail at any time & your loop has no way of reacting to it. You should do something like this :
stackoverflow.com