Properly escape bytearray data outside the ascii range when using a codec

Some codecs can't handle the range outside ascii properly and would then
fail to read the data back in correctly.

Backport of change 7df8b1ada4b23acedda5724b492c26a8e322648b from Qt 5.

Task-number: QTBUG-15543
Change-Id: I4c02921e787a939eeec0c7a11603b5896d756aef
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>