Use PwriteFully and write image header last

Prevent corrupted images if dex2oat gets killed or if the image
writer is interrupted during writing.

Bug: 22858531
Bug: 27561308

Change-Id: Ia882d23d672f93c90733fc59a1f6508b0985a011
4 files changed