Close file streams

This is mainly refactoring, without any new logic.

Bug: 148005911
Test: Refactoring, presubmits are sufficient
Change-Id: I3b9b35f4a952edc04357a2c1b265b1d0f346d515
2 files changed