Flush BufferedOutputStream correctly

This ensures that IOException due to writes are thrown in the main
code path instead of the exceptional code path.  Specifically for
HttpDownloader this ensures that IOUtils.closeQuietly does not swallow
a failed write.