Handle the end of stream