Only close stream if it exists