nullcheck before closing stream