cehck for null before closing streams

Change-Id: I23eae1cb582145fd18166417f0dc06d1666c3ba5