package com.bytedance.sdk.component.adexpress.YFl.Sg;

import com.bytedance.sdk.component.utils.YoT;
import com.ironsource.rb;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import org.json.JSONObject;
/* loaded from: classes2.dex */
public class qsH {
    private static com.bytedance.sdk.component.adexpress.YFl.tN.YFl YFl;

    public static void YFl() {
        FileInputStream fileInputStream;
        Throwable th;
        FileInputStream fileInputStream2 = null;
        try {
            File file = new File(wN.qsH(), "temp_pkg_info.json");
            Long valueOf = Long.valueOf(file.length());
            if (valueOf.longValue() > 0 && file.exists() && file.isFile()) {
                byte[] bArr = new byte[valueOf.intValue()];
                fileInputStream = new FileInputStream(file);
                try {
                    fileInputStream.read(bArr);
                    com.bytedance.sdk.component.adexpress.YFl.tN.YFl YFl2 = com.bytedance.sdk.component.adexpress.YFl.tN.YFl.YFl(new JSONObject(new String(bArr, rb.N)));
                    if (YFl2 != null) {
                        YFl = YFl2;
                        YFl.tN();
                    }
                    fileInputStream2 = fileInputStream;
                } catch (Throwable th2) {
                    th = th2;
                    try {
                        YoT.YFl("Version", "version init error", th);
                        if (fileInputStream != null) {
                            try {
                                fileInputStream.close();
                                return;
                            } catch (IOException unused) {
                                return;
                            }
                        }
                        return;
                    } catch (Throwable th3) {
                        if (fileInputStream != null) {
                            try {
                                fileInputStream.close();
                            } catch (IOException unused2) {
                            }
                        }
                        throw th3;
                    }
                }
            }
            if (fileInputStream2 != null) {
                try {
                    fileInputStream2.close();
                } catch (IOException unused3) {
                }
            }
        } catch (Throwable th4) {
            fileInputStream = null;
            th = th4;
        }
    }

    public static synchronized com.bytedance.sdk.component.adexpress.YFl.tN.YFl Sg() {
        com.bytedance.sdk.component.adexpress.YFl.tN.YFl yFl;
        synchronized (qsH.class) {
            yFl = YFl;
        }
        return yFl;
    }

    public static synchronized void YFl(com.bytedance.sdk.component.adexpress.YFl.tN.YFl yFl) {
        synchronized (qsH.class) {
            if (yFl != null) {
                if (yFl.DSW()) {
                    YFl = yFl;
                }
            }
        }
    }

    public static void tN() {
        wN.YFl(wN.qsH(), Sg(), "temp_pkg_info.json");
    }

    public static boolean YFl(String str) {
        return wN.YFl(Sg(), str);
    }

    public static boolean Sg(com.bytedance.sdk.component.adexpress.YFl.tN.YFl yFl) {
        return wN.tN(Sg(), yFl);
    }

    public static void AlY() {
        wN.Sg(wN.qsH(), Sg(), "temp_pkg_info.json");
        YFl = null;
    }
}
