[SPARK-3948][Shuffle]Fix stream corruption bug in sort-based shuffle

Kernel 2.6.32 bug will lead to unexpected behavior of transferTo in copyStream, and this will corrupt the shuffle output file in sort-based shuffle, which will somehow introduce PARSING_ERROR(2), deserialization error or offset out of range. Here fix this by adding append flag, also add some position checking code. Details can be seen in [SPARK-3948](https://issues.apache.org/jira/browse/SPARK-3948).
Thanks Josh, I think I start to know your concern. My previous modification may not well control the behavior of `transferTo` in all uses of it, but this brings less impact to the current code path. If we'd like to control it in all the places, we have to pass and verify the configuration in all the places where use `copyStream`, which is not so elegant in some codes which have to to get SparkConf. I will think a better way to address this. Thanks a lot.