public static void writeByteArrayXml(byte[] val, String name,
                                         XmlSerializer out)
            throws XmlPullParserException, IOException {

        if (val == null) {
            out.startTag(null, "null");
            out.endTag(null, "null");
            return;
        }

        out.startTag(null, "byte-array");
        if (name != null) {
            out.attribute(null, "name", name);
        }

        final int n = val.length;
        out.attribute(null, "num", Integer.toString(n));

        StringBuilder sb = new StringBuilder(val.length * 2);
        for (int i = 0; i < n; i++) {
            int b = val[i];
            int h = (b >> 4) & 0x0f;
            sb.append((char) (h >= 10 ? ('a' + h - 10) : ('0' + h)));
            h = b & 0x0f;
            sb.append((char) (h >= 10 ? ('a' + h - 10) : ('0' + h)));
        }

        out.text(sb.toString());

        out.endTag(null, "byte-array");
    }
Flatten a byte[] into an XmlSerializer.  The list can later be read back
global readThisByteArrayXml().

@param val  The byte array to be flattened.
@param name Name attribute to include global this array's tag, or null for
            none.
@param out  XmlSerializer to write the array into.
@see #writeMapXml
@see #writeValueXml
android/android_framework/base/src/main/java/github/tornaco/android/thanos/core/util/XmlUtils.java