package defpackage;

import android.content.Context;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.zip.GZIPInputStream;
import java.util.zip.ZipInputStream;

/* JADX INFO: loaded from: classes.dex */
@m38
public class il6 {
    public final pk6 a;
    public final r02 b;

    public static /* synthetic */ class a {
        public static final /* synthetic */ int[] a;

        static {
            int[] iArr = new int[cy2.values().length];
            a = iArr;
            try {
                iArr[1] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                a[2] = 2;
            } catch (NoSuchFieldError unused2) {
            }
        }
    }

    public il6(pk6 pk6Var, r02 r02Var) {
        this.a = pk6Var;
        this.b = r02Var;
    }

    public final bl5 a(Context context, String str, InputStream inputStream, String str2, String str3) {
        bl5 bl5VarG;
        cy2 cy2Var;
        if (str2 == null) {
            str2 = "application/json";
        }
        boolean zContains = str2.contains("application/zip");
        pk6 pk6Var = this.a;
        if (zContains || str2.contains("application/x-zip") || str2.contains("application/x-zip-compressed") || str.split("\\?")[0].endsWith(".lottie")) {
            gh5.a();
            cy2 cy2Var2 = cy2.ZIP;
            bl5VarG = str3 != null ? ek5.g(context, new ZipInputStream(new FileInputStream(pk6Var.d(str, inputStream, cy2Var2))), str) : ek5.g(context, new ZipInputStream(inputStream), null);
            cy2Var = cy2Var2;
        } else if (str2.contains("application/gzip") || str2.contains("application/x-gzip") || str.split("\\?")[0].endsWith(".tgs")) {
            gh5.a();
            cy2Var = cy2.GZIP;
            bl5VarG = str3 != null ? ek5.d(new GZIPInputStream(new FileInputStream(pk6Var.d(str, inputStream, cy2Var))), str) : ek5.d(new GZIPInputStream(inputStream), null);
        } else {
            gh5.a();
            cy2Var = cy2.JSON;
            bl5VarG = str3 != null ? ek5.d(new FileInputStream(pk6Var.d(str, inputStream, cy2Var).getAbsolutePath()), str) : ek5.d(inputStream, null);
        }
        if (str3 != null && bl5VarG.a != null) {
            File file = new File(pk6Var.c(), pk6.a(str, cy2Var, true));
            File file2 = new File(file.getAbsolutePath().replace(".temp", ""));
            boolean zRenameTo = file.renameTo(file2);
            file2.toString();
            gh5.a();
            if (!zRenameTo) {
                gh5.b("Unable to rename cache file " + file.getAbsolutePath() + " to " + file2.getAbsolutePath() + ".");
            }
        }
        return bl5VarG;
    }
}
