package com.ss.android.ugc.effectmanager.common.utils;

import X.2sG;
import X.M12;
import android.content.res.AssetManager;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.ss.android.ugc.effectmanager.common.logger.EPLog;
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.InputStreamReader;

public final class AssetUtils {
    public static final AssetUtils INSTANCE = new AssetUtils();

    static {
        Covode.recordClassIndex(125307);
    }

    public static final String loadJson(AssetManager assetManager, String str) {
        BufferedReader bufferedReader;
        InputStreamReader inputStreamReader;
        MethodCollector.i(9360);
        M12.LIZ(assetManager);
        InputStreamReader inputStreamReader2 = null;
        if (str != null) {
            try {
                inputStreamReader = new InputStreamReader(assetManager.open(str));
                try {
                    bufferedReader = new BufferedReader(inputStreamReader);
                } catch (Exception e) {
                    e = e;
                    bufferedReader = null;
                    try {
                        EPLog.e("AssetUtils", "#loadJson::jsonFilePath=".concat(String.valueOf(str)), e);
                        CloseUtil.close(inputStreamReader);
                        CloseUtil.close(bufferedReader);
                        MethodCollector.o(9360);
                        return null;
                    } catch (Throwable th) {
                        th = th;
                    }
                } catch (Throwable th2) {
                    th = th2;
                    bufferedReader = null;
                    inputStreamReader2 = inputStreamReader;
                    CloseUtil.close(inputStreamReader2);
                    CloseUtil.close(bufferedReader);
                    MethodCollector.o(9360);
                    throw th;
                }
            } catch (Exception e2) {
                e = e2;
                bufferedReader = null;
                inputStreamReader = null;
                EPLog.e("AssetUtils", "#loadJson::jsonFilePath=".concat(String.valueOf(str)), e);
                CloseUtil.close(inputStreamReader);
                CloseUtil.close(bufferedReader);
                MethodCollector.o(9360);
                return null;
            } catch (Throwable th3) {
                th = th3;
                bufferedReader = null;
                CloseUtil.close(inputStreamReader2);
                CloseUtil.close(bufferedReader);
                MethodCollector.o(9360);
                throw th;
            }
            try {
                StringBuilder sb = new StringBuilder();
                2sG r1 = new 2sG();
                while (true) {
                    String readLine = bufferedReader.readLine();
                    r1.element = readLine;
                    if (readLine != null) {
                        sb.append((String) r1.element);
                    } else {
                        String sb2 = sb.toString();
                        CloseUtil.close(inputStreamReader);
                        CloseUtil.close(bufferedReader);
                        MethodCollector.o(9360);
                        return sb2;
                    }
                }
            } catch (Exception e3) {
                e = e3;
                EPLog.e("AssetUtils", "#loadJson::jsonFilePath=".concat(String.valueOf(str)), e);
                CloseUtil.close(inputStreamReader);
                CloseUtil.close(bufferedReader);
                MethodCollector.o(9360);
                return null;
            }
        } else {
            CloseUtil.close((Closeable) null);
            CloseUtil.close((Closeable) null);
            MethodCollector.o(9360);
            return null;
        }
    }
}
