[SP-1254] - Regression PIR-994

Fixed encoding issue with Metadata domain save, by recovering old code and fixing issue in ByteArrayInputStream creation.
Cherry picked from 0429c31e0469725d79a0e80cc56bf6cfc673be10