package c.f.j.c; import c.f.b.b.d; import c.f.b.b.h; import c.f.b.b.i; import c.f.d.g.g; import c.f.d.g.j; import c.f.j.j.e; import c.f.j.r.b; import com.airbnb.lottie.parser.AnimatableValueParser; import com.facebook.cache.common.CacheKey; import com.facebook.common.memory.PooledByteBuffer; import java.io.FileInputStream; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.concurrent.Executor; import java.util.concurrent.atomic.AtomicBoolean; /* compiled from: BufferedDiskCache */ public class f { public final h a; public final g b; /* renamed from: c reason: collision with root package name */ public final j f420c; public final Executor d; public final Executor e; public final a0 f = new a0(); public final r g; /* compiled from: BufferedDiskCache */ public class a implements Runnable { public final /* synthetic */ CacheKey i; public final /* synthetic */ e j; public a(Object obj, CacheKey cacheKey, e eVar) { this.i = cacheKey; this.j = eVar; } /* JADX WARNING: Code restructure failed: missing block: B:10:0x002c, code lost: if (r1 != null) goto L_0x002e; */ /* JADX WARNING: Code restructure failed: missing block: B:11:0x002e, code lost: r1.close(); */ /* JADX WARNING: Code restructure failed: missing block: B:12:0x0031, code lost: throw r0; */ /* JADX WARNING: Code restructure failed: missing block: B:8:0x001e, code lost: r0 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:9:0x001f, code lost: r4.k.f.d(r4.i, r4.j); r1 = r4.j; */ @Override // java.lang.Runnable public void run() { f.b(f.this, this.i, this.j); f.this.f.d(this.i, this.j); e eVar = this.j; if (eVar != null) { eVar.close(); } } } public f(h hVar, g gVar, j jVar, Executor executor, Executor executor2, r rVar) { this.a = hVar; this.b = gVar; this.f420c = jVar; this.d = executor; this.e = executor2; this.g = rVar; } /* JADX INFO: finally extract failed */ public static PooledByteBuffer a(f fVar, CacheKey cacheKey) throws IOException { Objects.requireNonNull(fVar); try { cacheKey.b(); int i = c.f.d.e.a.a; c.f.a.a b = ((d) fVar.a).b(cacheKey); if (b == null) { cacheKey.b(); Objects.requireNonNull((z) fVar.g); return null; } cacheKey.b(); Objects.requireNonNull((z) fVar.g); FileInputStream fileInputStream = new FileInputStream(b.a); try { PooledByteBuffer d = fVar.b.d(fileInputStream, (int) b.a()); fileInputStream.close(); cacheKey.b(); return d; } catch (Throwable th) { fileInputStream.close(); throw th; } } catch (IOException e) { c.f.d.e.a.n(f.class, e, "Exception reading from cache for %s", cacheKey.b()); Objects.requireNonNull((z) fVar.g); throw e; } } public static void b(f fVar, CacheKey cacheKey, e eVar) { Objects.requireNonNull(fVar); cacheKey.b(); int i = c.f.d.e.a.a; try { ((d) fVar.a).d(cacheKey, new h(fVar, eVar)); Objects.requireNonNull((z) fVar.g); cacheKey.b(); } catch (IOException e) { c.f.d.e.a.n(f.class, e, "Failed to write to disk-cache for key %s", cacheKey.b()); } } public void c(CacheKey cacheKey) { d dVar = (d) this.a; Objects.requireNonNull(dVar); try { synchronized (dVar.q) { List I0 = AnimatableValueParser.I0(cacheKey); int i = 0; while (true) { ArrayList arrayList = (ArrayList) I0; if (i < arrayList.size()) { String str = (String) arrayList.get(i); if (dVar.k.c(str, cacheKey)) { dVar.h.add(str); return; } i++; } else { return; } } } } catch (IOException unused) { i a2 = i.a(); a2.d = cacheKey; Objects.requireNonNull((c.f.b.a.e) dVar.g); a2.b(); } } /* JADX DEBUG: Type inference failed for r1v9. Raw type applied. Possible types: z.g, z.g */ /* JADX DEBUG: Type inference failed for r1v10. Raw type applied. Possible types: z.g, z.g */ public final z.g d(CacheKey cacheKey, e eVar) { cacheKey.b(); int i = c.f.d.e.a.a; Objects.requireNonNull((z) this.g); Executor executor = z.g.a; if (eVar instanceof Boolean) { return ((Boolean) eVar).booleanValue() ? z.g.f2885c : z.g.d; } z.g gVar = new z.g<>(); if (gVar.h(eVar)) { return gVar; } throw new IllegalStateException("Cannot set the result of a completed task."); } /* JADX INFO: finally extract failed */ public z.g e(CacheKey cacheKey, AtomicBoolean atomicBoolean) { z.g gVar; try { b.b(); e a2 = this.f.a(cacheKey); if (a2 != null) { z.g d = d(cacheKey, a2); b.b(); return d; } try { gVar = z.g.a(new e(this, null, atomicBoolean, cacheKey), this.d); } catch (Exception e) { c.f.d.e.a.n(f.class, e, "Failed to schedule disk-cache read for %s", ((c.f.b.a.f) cacheKey).a); gVar = z.g.c(e); } b.b(); return gVar; } catch (Throwable th) { b.b(); throw th; } } /* JADX INFO: finally extract failed */ public void f(CacheKey cacheKey, e eVar) { try { b.b(); Objects.requireNonNull(cacheKey); AnimatableValueParser.j(Boolean.valueOf(e.t(eVar))); this.f.b(cacheKey, eVar); e a2 = e.a(eVar); try { this.e.execute(new a(null, cacheKey, a2)); } catch (Exception e) { c.f.d.e.a.n(f.class, e, "Failed to schedule disk-cache write for %s", cacheKey.b()); this.f.d(cacheKey, eVar); if (a2 != null) { a2.close(); } } b.b(); } catch (Throwable th) { b.b(); throw th; } } }