Files
Daniel Elliott c080f0d97f Add Discord community version (64-bit only)
- Added realracing3-community.apk (71.57 MB)
- Removed 32-bit support (armeabi-v7a)
- Only includes arm64-v8a libraries
- Decompiled source code included
- Added README-community.md with analysis
2026-02-18 15:48:36 -08:00

350 lines
12 KiB
Java

package csdk.glucustomersupport.util;
import android.annotation.TargetApi;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.JsonReader;
import android.util.JsonToken;
import com.fyber.inneractive.sdk.external.InneractiveMediationDefs;
import csdk.gluads.Consts;
import java.io.IOException;
import java.io.StringReader;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONStringer;
/* loaded from: classes4.dex */
public class JsonUtil {
public static Map<String, Object> parseJsonObject(String str) throws JSONException {
return Api11.parseJsonObject(str);
}
public static List<Object> parseJsonList(String str) throws JSONException {
return Api11.parseJsonArray(str);
}
public static Map<String, Object> toMap(Bundle bundle) {
return (Map) toSimpleJavaTypes(bundle);
}
public static Map<String, Object> toMap(JSONObject jSONObject) {
return (Map) toSimpleJavaTypes(jSONObject);
}
public static Map<String, Object> toMap(String str) {
if (TextUtils.isEmpty(str)) {
return null;
}
try {
return parseJsonObject(str);
} catch (JSONException e) {
throw GluUtil.propagate(e);
}
}
public static List<Object> toList(JSONObject jSONObject) {
return (List) toSimpleJavaTypes(jSONObject);
}
public static List<Object> toList(String str) {
if (TextUtils.isEmpty(str)) {
return null;
}
try {
return parseJsonList(str);
} catch (JSONException e) {
throw GluUtil.propagate(e);
}
}
public static String toJson(Object obj) {
JSONStringer jSONStringer = new JSONStringer();
try {
value(jSONStringer, obj);
return jSONStringer.toString();
} catch (JSONException e) {
throw GluUtil.propagate(e);
}
}
public static void optKeyValue(JSONStringer jSONStringer, String str, Object obj) throws JSONException {
if (obj != null) {
jSONStringer.key(str);
value(jSONStringer, obj);
}
}
public static void value(JSONStringer jSONStringer, Object obj) throws JSONException {
if (obj == null) {
jSONStringer.value(obj);
return;
}
if (obj instanceof ISerializableJsonObject) {
jSONStringer.object();
((ISerializableJsonObject) obj).write(jSONStringer);
jSONStringer.endObject();
return;
}
if ((obj instanceof Number) || (obj instanceof Boolean) || (obj instanceof CharSequence) || (obj instanceof Character)) {
jSONStringer.value(obj);
return;
}
if (obj instanceof Map) {
serializeMap(jSONStringer, (Map) obj);
return;
}
if (obj instanceof Iterable) {
serializeIterable(jSONStringer, (Iterable) obj);
return;
}
if (obj.getClass().isArray()) {
serializeArray(jSONStringer, obj);
} else if (obj instanceof Throwable) {
serializeThrowable(jSONStringer, (Throwable) obj);
} else {
serializeDefaultObject(jSONStringer, obj);
}
}
private static void serializeMap(JSONStringer jSONStringer, Map<?, ?> map) throws JSONException {
Iterator<?> it = map.keySet().iterator();
while (it.hasNext()) {
if (!(it.next() instanceof CharSequence)) {
serializeMapWithNonStringKeys(jSONStringer, map);
return;
}
}
jSONStringer.object();
for (Map.Entry<?, ?> entry : map.entrySet()) {
jSONStringer.key(entry.getKey().toString());
value(jSONStringer, entry.getValue());
}
jSONStringer.endObject();
}
private static void serializeMapWithNonStringKeys(JSONStringer jSONStringer, Map<?, ?> map) throws JSONException {
jSONStringer.object();
optKeyValue(jSONStringer, "cls", "flatmap");
jSONStringer.key(Consts.KEY_TAPJOY_USER_ID_VERSION).array();
for (Map.Entry<?, ?> entry : map.entrySet()) {
jSONStringer.array();
value(jSONStringer, entry.getKey());
value(jSONStringer, entry.getValue());
jSONStringer.endArray();
}
jSONStringer.endArray();
jSONStringer.endObject();
}
private static void serializeIterable(JSONStringer jSONStringer, Iterable<?> iterable) throws JSONException {
jSONStringer.array();
Iterator<?> it = iterable.iterator();
while (it.hasNext()) {
value(jSONStringer, it.next());
}
jSONStringer.endArray();
}
private static void serializeArray(JSONStringer jSONStringer, Object obj) throws JSONException {
int length = Array.getLength(obj);
jSONStringer.array();
for (int i = 0; i < length; i++) {
value(jSONStringer, Array.get(obj, i));
}
jSONStringer.endArray();
}
private static void serializeThrowable(JSONStringer jSONStringer, Throwable th) throws JSONException {
jSONStringer.object();
optKeyValue(jSONStringer, "cls", th.getClass().getSimpleName());
optKeyValue(jSONStringer, InneractiveMediationDefs.GENDER_MALE, th.getMessage());
jSONStringer.endObject();
}
private static void serializeDefaultObject(JSONStringer jSONStringer, Object obj) throws JSONException {
jSONStringer.object();
optKeyValue(jSONStringer, "str", obj.toString());
jSONStringer.endObject();
}
private static Object toSimpleJavaTypes(Object obj) {
if (obj == null || (obj instanceof String) || (obj instanceof Number) || (obj instanceof Boolean)) {
return obj;
}
if ((obj instanceof CharSequence) || (obj instanceof Character)) {
return obj.toString();
}
if (obj instanceof Iterable) {
ArrayList arrayList = new ArrayList();
Iterator it = ((Iterable) obj).iterator();
while (it.hasNext()) {
arrayList.add(toSimpleJavaTypes(it.next()));
}
return arrayList;
}
int i = 0;
if (obj.getClass().isArray()) {
ArrayList arrayList2 = new ArrayList();
int length = Array.getLength(obj);
while (i < length) {
arrayList2.add(toSimpleJavaTypes(Array.get(obj, i)));
i++;
}
return arrayList2;
}
if (obj instanceof Bundle) {
Map createMap = GluUtil.createMap();
Bundle bundle = (Bundle) obj;
for (String str : bundle.keySet()) {
createMap.put(str, toSimpleJavaTypes(bundle.get(str)));
}
return createMap;
}
if (obj instanceof JSONArray) {
ArrayList arrayList3 = new ArrayList();
JSONArray jSONArray = (JSONArray) obj;
while (i < jSONArray.length()) {
arrayList3.add(toSimpleJavaTypes(jSONArray.opt(i)));
i++;
}
return arrayList3;
}
if (obj instanceof JSONObject) {
Map createMap2 = GluUtil.createMap();
JSONObject jSONObject = (JSONObject) obj;
Iterator<String> keys = jSONObject.keys();
while (keys.hasNext()) {
String next = keys.next();
createMap2.put(next, toSimpleJavaTypes(jSONObject.opt(next)));
}
return createMap2;
}
if (obj == JSONObject.NULL) {
return null;
}
throw new IllegalArgumentException(String.format("Unsupported type %s", obj.getClass()));
}
@TargetApi(11)
public static class Api11 {
public static Map<String, Object> parseJsonObject(String str) throws JSONException {
JsonReader jsonReader;
JsonReader jsonReader2 = null;
try {
try {
jsonReader = new JsonReader(new StringReader(str));
} catch (Throwable th) {
th = th;
}
} catch (IOException e) {
e = e;
}
try {
jsonReader.setLenient(true);
Map<String, Object> parseJsonObject = parseJsonObject(jsonReader);
try {
jsonReader.close();
return parseJsonObject;
} catch (IOException e2) {
throw GluUtil.propagate(e2);
}
} catch (IOException e3) {
e = e3;
throw GluUtil.propagate(e);
} catch (Throwable th2) {
th = th2;
jsonReader2 = jsonReader;
if (jsonReader2 != null) {
try {
jsonReader2.close();
} catch (IOException e4) {
throw GluUtil.propagate(e4);
}
}
throw th;
}
}
public static List<Object> parseJsonArray(String str) throws JSONException {
try {
JsonReader jsonReader = new JsonReader(new StringReader(str));
jsonReader.setLenient(true);
return parseJsonArray(jsonReader);
} catch (IOException e) {
throw GluUtil.propagate(e);
}
}
public static Object parseJsonValue(JsonReader jsonReader) throws JSONException, IOException {
JsonToken peek = jsonReader.peek();
if (peek == JsonToken.BEGIN_OBJECT) {
return parseJsonObject(jsonReader);
}
if (peek == JsonToken.BEGIN_ARRAY) {
return parseJsonArray(jsonReader);
}
if (peek == JsonToken.BOOLEAN) {
return Boolean.valueOf(jsonReader.nextBoolean());
}
if (peek == JsonToken.NULL) {
jsonReader.nextNull();
return null;
}
if (peek == JsonToken.NUMBER) {
String nextString = jsonReader.nextString();
if (nextString.contains(Consts.STRING_PERIOD) || nextString.contains("e") || nextString.contains("E")) {
return Double.valueOf(Double.parseDouble(nextString));
}
return Long.valueOf(Long.parseLong(nextString));
}
if (peek == JsonToken.STRING) {
return jsonReader.nextString();
}
throw new JSONException("Unexpected token " + peek);
}
public static Map<String, Object> parseJsonObject(JsonReader jsonReader) throws JSONException, IOException {
Map<String, Object> createMap = GluUtil.createMap();
jsonReader.beginObject();
while (true) {
JsonToken peek = jsonReader.peek();
if (peek == JsonToken.END_OBJECT) {
jsonReader.endObject();
return createMap;
}
if (peek == JsonToken.NAME) {
createMap.put(jsonReader.nextName(), parseJsonValue(jsonReader));
} else {
throw new JSONException("Expected } or name but found " + peek);
}
}
}
public static List<Object> parseJsonArray(JsonReader jsonReader) throws JSONException, IOException {
ArrayList arrayList = new ArrayList();
jsonReader.beginArray();
while (jsonReader.peek() != JsonToken.END_ARRAY) {
arrayList.add(parseJsonValue(jsonReader));
}
jsonReader.endArray();
return arrayList;
}
}
public static class Api1 {
public static Map<String, Object> parseJsonObject(String str) throws JSONException {
return JsonUtil.toMap(new JSONObject(str));
}
public static List<Object> parseJsonArray(String str) throws JSONException {
return JsonUtil.toList(new JSONObject(str));
}
}
}