closing stream after reading from it