package com.ta.utdid2.b.a; import a.f; import a01.a; import a30.h; import android.util.Xml; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlSerializer; public class e { public static final void a(Map map, OutputStream outputStream) throws XmlPullParserException, IOException { a aVar = new a(); aVar.setOutput(outputStream, "utf-8"); aVar.startDocument(null, Boolean.TRUE); aVar.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); a(map, (String) null, (XmlSerializer) aVar); aVar.endDocument(); } private static Object b(XmlPullParser xmlPullParser, String[] strArr) throws XmlPullParserException, IOException { int next; Object obj = null; String attributeValue = xmlPullParser.getAttributeValue(null, "name"); String name = xmlPullParser.getName(); if (!name.equals("null")) { if (name.equals("string")) { String str = ""; while (true) { int next2 = xmlPullParser.next(); if (next2 == 1) { throw new XmlPullParserException("Unexpected end of document in <string>"); } else if (next2 == 3) { if (xmlPullParser.getName().equals("string")) { strArr[0] = attributeValue; return str; } StringBuilder h12 = f.h("Unexpected end tag in <string>: "); h12.append(xmlPullParser.getName()); throw new XmlPullParserException(h12.toString()); } else if (next2 == 4) { StringBuilder h13 = f.h(str); h13.append(xmlPullParser.getText()); str = h13.toString(); } else if (next2 == 2) { StringBuilder h14 = f.h("Unexpected start tag in <string>: "); h14.append(xmlPullParser.getName()); throw new XmlPullParserException(h14.toString()); } } } else if (name.equals("int")) { obj = Integer.valueOf(Integer.parseInt(xmlPullParser.getAttributeValue(null, "value"))); } else if (name.equals("long")) { obj = Long.valueOf(xmlPullParser.getAttributeValue(null, "value")); } else if (name.equals("float")) { obj = Float.valueOf(xmlPullParser.getAttributeValue(null, "value")); } else if (name.equals("double")) { obj = Double.valueOf(xmlPullParser.getAttributeValue(null, "value")); } else if (name.equals("boolean")) { obj = Boolean.valueOf(xmlPullParser.getAttributeValue(null, "value")); } else if (name.equals("int-array")) { xmlPullParser.next(); int[] a5 = m96a(xmlPullParser, "int-array", strArr); strArr[0] = attributeValue; return a5; } else if (name.equals("map")) { xmlPullParser.next(); HashMap a12 = m95a(xmlPullParser, "map", strArr); strArr[0] = attributeValue; return a12; } else if (name.equals("list")) { xmlPullParser.next(); ArrayList a13 = a(xmlPullParser, "list", strArr); strArr[0] = attributeValue; return a13; } else { throw new XmlPullParserException(a40.f.g("Unknown tag: ", name)); } } do { next = xmlPullParser.next(); if (next == 1) { throw new XmlPullParserException(a.g("Unexpected end of document in <", name, ">")); } else if (next == 3) { if (xmlPullParser.getName().equals(name)) { strArr[0] = attributeValue; return obj; } StringBuilder g3 = h.g("Unexpected end tag in <", name, ">: "); g3.append(xmlPullParser.getName()); throw new XmlPullParserException(g3.toString()); } else if (next == 4) { StringBuilder g6 = h.g("Unexpected text in <", name, ">: "); g6.append(xmlPullParser.getName()); throw new XmlPullParserException(g6.toString()); } } while (next != 2); StringBuilder g12 = h.g("Unexpected start tag in <", name, ">: "); g12.append(xmlPullParser.getName()); throw new XmlPullParserException(g12.toString()); } public static final void a(Map map, String str, XmlSerializer xmlSerializer) throws XmlPullParserException, IOException { if (map == null) { xmlSerializer.startTag(null, "null"); xmlSerializer.endTag(null, "null"); return; } xmlSerializer.startTag(null, "map"); if (str != null) { xmlSerializer.attribute(null, "name", str); } for (Map.Entry entry : map.entrySet()) { a(entry.getValue(), (String) entry.getKey(), xmlSerializer); } xmlSerializer.endTag(null, "map"); } public static final void a(List list, String str, XmlSerializer xmlSerializer) throws XmlPullParserException, IOException { if (list == null) { xmlSerializer.startTag(null, "null"); xmlSerializer.endTag(null, "null"); return; } xmlSerializer.startTag(null, "list"); if (str != null) { xmlSerializer.attribute(null, "name", str); } int size = list.size(); for (int i = 0; i < size; i++) { a(list.get(i), (String) null, xmlSerializer); } xmlSerializer.endTag(null, "list"); } public static final void a(byte[] bArr, String str, XmlSerializer xmlSerializer) throws XmlPullParserException, IOException { if (bArr == null) { xmlSerializer.startTag(null, "null"); xmlSerializer.endTag(null, "null"); return; } xmlSerializer.startTag(null, "byte-array"); if (str != null) { xmlSerializer.attribute(null, "name", str); } int length = bArr.length; xmlSerializer.attribute(null, "num", Integer.toString(length)); StringBuilder sb2 = new StringBuilder(bArr.length * 2); for (byte b : bArr) { int i = b >> 4; sb2.append(i >= 10 ? (i + 97) - 10 : i + 48); int i3 = b & 255; sb2.append(i3 >= 10 ? (i3 + 97) - 10 : i3 + 48); } xmlSerializer.text(sb2.toString()); xmlSerializer.endTag(null, "byte-array"); } public static final void a(int[] iArr, String str, XmlSerializer xmlSerializer) throws XmlPullParserException, IOException { if (iArr == null) { xmlSerializer.startTag(null, "null"); xmlSerializer.endTag(null, "null"); return; } xmlSerializer.startTag(null, "int-array"); if (str != null) { xmlSerializer.attribute(null, "name", str); } int length = iArr.length; xmlSerializer.attribute(null, "num", Integer.toString(length)); for (int i : iArr) { xmlSerializer.startTag(null, "item"); xmlSerializer.attribute(null, "value", Integer.toString(i)); xmlSerializer.endTag(null, "item"); } xmlSerializer.endTag(null, "int-array"); } public static final void a(Object obj, String str, XmlSerializer xmlSerializer) throws XmlPullParserException, IOException { String str2; if (obj == null) { xmlSerializer.startTag(null, "null"); if (str != null) { xmlSerializer.attribute(null, "name", str); } xmlSerializer.endTag(null, "null"); } else if (obj instanceof String) { xmlSerializer.startTag(null, "string"); if (str != null) { xmlSerializer.attribute(null, "name", str); } xmlSerializer.text(obj.toString()); xmlSerializer.endTag(null, "string"); } else { if (obj instanceof Integer) { str2 = "int"; } else if (obj instanceof Long) { str2 = "long"; } else if (obj instanceof Float) { str2 = "float"; } else if (obj instanceof Double) { str2 = "double"; } else if (obj instanceof Boolean) { str2 = "boolean"; } else if (obj instanceof byte[]) { a((byte[]) obj, str, xmlSerializer); return; } else if (obj instanceof int[]) { a((int[]) obj, str, xmlSerializer); return; } else if (obj instanceof Map) { a((Map) obj, str, xmlSerializer); return; } else if (obj instanceof List) { a((List) obj, str, xmlSerializer); return; } else if (obj instanceof CharSequence) { xmlSerializer.startTag(null, "string"); if (str != null) { xmlSerializer.attribute(null, "name", str); } xmlSerializer.text(obj.toString()); xmlSerializer.endTag(null, "string"); return; } else { throw new RuntimeException(h.a.k("writeValueXml: unable to write value ", obj)); } xmlSerializer.startTag(null, str2); if (str != null) { xmlSerializer.attribute(null, "name", str); } xmlSerializer.attribute(null, "value", obj.toString()); xmlSerializer.endTag(null, str2); } } public static final HashMap a(InputStream inputStream) throws XmlPullParserException, IOException { XmlPullParser newPullParser = Xml.newPullParser(); newPullParser.setInput(inputStream, null); return (HashMap) a(newPullParser, new String[1]); } /* renamed from: a reason: collision with other method in class */ public static final HashMap m95a(XmlPullParser xmlPullParser, String str, String[] strArr) throws XmlPullParserException, IOException { HashMap hashMap = new HashMap(); int eventType = xmlPullParser.getEventType(); do { if (eventType == 2) { Object b = b(xmlPullParser, strArr); if (strArr[0] != null) { hashMap.put(strArr[0], b); } else { StringBuilder h12 = f.h("Map value without name attribute: "); h12.append(xmlPullParser.getName()); throw new XmlPullParserException(h12.toString()); } } else if (eventType == 3) { if (xmlPullParser.getName().equals(str)) { return hashMap; } StringBuilder g3 = h.g("Expected ", str, " end tag at: "); g3.append(xmlPullParser.getName()); throw new XmlPullParserException(g3.toString()); } eventType = xmlPullParser.next(); } while (eventType != 1); throw new XmlPullParserException(a.g("Document ended before ", str, " end tag")); } public static final ArrayList a(XmlPullParser xmlPullParser, String str, String[] strArr) throws XmlPullParserException, IOException { ArrayList arrayList = new ArrayList(); int eventType = xmlPullParser.getEventType(); do { if (eventType == 2) { arrayList.add(b(xmlPullParser, strArr)); } else if (eventType == 3) { if (xmlPullParser.getName().equals(str)) { return arrayList; } StringBuilder g3 = h.g("Expected ", str, " end tag at: "); g3.append(xmlPullParser.getName()); throw new XmlPullParserException(g3.toString()); } eventType = xmlPullParser.next(); } while (eventType != 1); throw new XmlPullParserException(a.g("Document ended before ", str, " end tag")); } /* renamed from: a reason: collision with other method in class */ public static final int[] m96a(XmlPullParser xmlPullParser, String str, String[] strArr) throws XmlPullParserException, IOException { try { int[] iArr = new int[Integer.parseInt(xmlPullParser.getAttributeValue(null, "num"))]; int i = 0; int eventType = xmlPullParser.getEventType(); do { if (eventType == 2) { if (xmlPullParser.getName().equals("item")) { try { iArr[i] = Integer.parseInt(xmlPullParser.getAttributeValue(null, "value")); } catch (NullPointerException unused) { throw new XmlPullParserException("Need value attribute in item"); } catch (NumberFormatException unused2) { throw new XmlPullParserException("Not a number in value attribute in item"); } } else { StringBuilder h12 = f.h("Expected item tag at: "); h12.append(xmlPullParser.getName()); throw new XmlPullParserException(h12.toString()); } } else if (eventType == 3) { if (xmlPullParser.getName().equals(str)) { return iArr; } if (xmlPullParser.getName().equals("item")) { i++; } else { StringBuilder g3 = h.g("Expected ", str, " end tag at: "); g3.append(xmlPullParser.getName()); throw new XmlPullParserException(g3.toString()); } } eventType = xmlPullParser.next(); } while (eventType != 1); throw new XmlPullParserException(a.g("Document ended before ", str, " end tag")); } catch (NullPointerException unused3) { throw new XmlPullParserException("Need num attribute in byte-array"); } catch (NumberFormatException unused4) { throw new XmlPullParserException("Not a number in num attribute in byte-array"); } } public static final Object a(XmlPullParser xmlPullParser, String[] strArr) throws XmlPullParserException, IOException { int eventType = xmlPullParser.getEventType(); while (eventType != 2) { if (eventType == 3) { StringBuilder h12 = f.h("Unexpected end tag at: "); h12.append(xmlPullParser.getName()); throw new XmlPullParserException(h12.toString()); } else if (eventType != 4) { try { eventType = xmlPullParser.next(); if (eventType == 1) { throw new XmlPullParserException("Unexpected end of document"); } } catch (Exception unused) { StringBuilder h13 = f.h("Unexpected call next(): "); h13.append(xmlPullParser.getName()); throw new XmlPullParserException(h13.toString()); } } else { StringBuilder h14 = f.h("Unexpected text: "); h14.append(xmlPullParser.getText()); throw new XmlPullParserException(h14.toString()); } } return b(xmlPullParser, strArr); } }