package defpackage;

import android.util.Log;
import defpackage.bc2;
import defpackage.ec2;
import defpackage.fc2;
import java.io.File;
import java.io.IOException;
import java.util.Objects;

/* JADX INFO: loaded from: classes.dex */
public class jc2 implements bc2 {
    public final File b;
    public final long c;
    public fc2 e;
    public final ec2 d = new ec2();
    public final aa8 a = new aa8();

    public jc2(File file, long j) {
        this.b = file;
        this.c = j;
    }

    @Override // defpackage.bc2
    public final File a(v25 v25Var) {
        String strA = this.a.a(v25Var);
        if (Log.isLoggable("DiskLruCacheWrapper", 2)) {
            Objects.toString(v25Var);
        }
        try {
            fc2.e eVarN = c().n(strA);
            if (eVarN != null) {
                return eVarN.a[0];
            }
            return null;
        } catch (IOException e) {
            if (!Log.isLoggable("DiskLruCacheWrapper", 5)) {
                return null;
            }
            Log.w("DiskLruCacheWrapper", "Unable to get from disk cache", e);
            return null;
        }
    }

    @Override // defpackage.bc2
    public final void b(v25 v25Var, bc2.b bVar) {
        ec2.a aVar;
        boolean z;
        String strA = this.a.a(v25Var);
        ec2 ec2Var = this.d;
        synchronized (ec2Var) {
            aVar = (ec2.a) ec2Var.a.get(strA);
            if (aVar == null) {
                ec2.b bVar2 = ec2Var.b;
                synchronized (bVar2.a) {
                    aVar = (ec2.a) bVar2.a.poll();
                }
                if (aVar == null) {
                    aVar = new ec2.a();
                }
                ec2Var.a.put(strA, aVar);
            }
            aVar.b++;
        }
        aVar.a.lock();
        try {
            if (Log.isLoggable("DiskLruCacheWrapper", 2)) {
                Objects.toString(v25Var);
            }
            try {
                fc2 fc2VarC = c();
                if (fc2VarC.n(strA) == null) {
                    fc2.c cVarK = fc2VarC.k(strA);
                    if (cVarK == null) {
                        throw new IllegalStateException("Had two simultaneous puts for: ".concat(strA));
                    }
                    try {
                        if (bVar.a(cVarK.b())) {
                            fc2.a(fc2.this, cVarK, true);
                            cVarK.c = true;
                        }
                        if (!z) {
                            try {
                                cVarK.a();
                            } catch (IOException unused) {
                            }
                        }
                    } finally {
                        if (!cVarK.c) {
                            try {
                                cVarK.a();
                            } catch (IOException unused2) {
                            }
                        }
                    }
                }
            } catch (IOException e) {
                if (Log.isLoggable("DiskLruCacheWrapper", 5)) {
                    Log.w("DiskLruCacheWrapper", "Unable to put to disk cache", e);
                }
            }
        } finally {
            this.d.a(strA);
        }
    }

    public final synchronized fc2 c() {
        try {
            if (this.e == null) {
                this.e = fc2.u(this.b, this.c);
            }
        } catch (Throwable th) {
            throw th;
        }
        return this.e;
    }

    @Override // defpackage.bc2
    public final synchronized void clear() {
        try {
            try {
                c().d();
            } catch (IOException e) {
                if (Log.isLoggable("DiskLruCacheWrapper", 5)) {
                    Log.w("DiskLruCacheWrapper", "Unable to clear disk cache or disk cache cleared externally", e);
                }
                synchronized (this) {
                    this.e = null;
                }
            }
            synchronized (this) {
                this.e = null;
            }
        } catch (Throwable th) {
            synchronized (this) {
                this.e = null;
                throw th;
            }
        }
    }
}
