SPARK-2532: Minimal shuffle consolidation fixes

All changes from this PR are by @mridulm and are drawn from his work in #1609. This patch is intended to fix all major issues related to shuffle file consolidation that @mridulm found, while minimizing changes to the code, with the hope that it may be more easily merged into 1.1.

This patch is **not** intended as a replacement for #1609, which provides many additional benefits, including fixes to ExternalAppendOnlyMap, improvements to DiskBlockObjectWriter's API, and several new unit tests.

If it is feasible to merge #1609 for the 1.1 deadline, that is a preferable option.
In the use of writers in HashShuffleWriter, it is possible for a closed stream to be reverted (if some other stream's close failed for example).
In the above, that will leave this file with leftover data - I am not sure what the impact of this would be.