package okhttp3.internal.cache; import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; import java.util.NoSuchElementException; import o.C14866gag; import o.C14957gcv; import o.InterfaceC14931gcN; import okhttp3.internal.cache.DiskLruCache; /* loaded from: classes.dex */ public final class DiskLruCache$snapshots$1 implements Iterator, InterfaceC14931gcN { private final Iterator delegate; private DiskLruCache.Snapshot nextSnapshot; private DiskLruCache.Snapshot removeSnapshot; final DiskLruCache this$0; /* JADX INFO: Access modifiers changed from: package-private */ public DiskLruCache$snapshots$1(DiskLruCache diskLruCache) { this.this$0 = diskLruCache; Iterator it = new ArrayList(diskLruCache.getLruEntries$okhttp().values()).iterator(); C14957gcv.c(it, ""); this.delegate = it; } @Override // java.util.Iterator public final boolean hasNext() { if (this.nextSnapshot != null) { return true; } DiskLruCache diskLruCache = this.this$0; synchronized (diskLruCache) { if (diskLruCache.getClosed$okhttp()) { return false; } while (this.delegate.hasNext()) { DiskLruCache.Entry next = this.delegate.next(); DiskLruCache.Snapshot snapshot$okhttp = next == null ? null : next.snapshot$okhttp(); if (snapshot$okhttp != null) { this.nextSnapshot = snapshot$okhttp; return true; } } C14866gag c14866gag = C14866gag.c; return false; } } @Override // java.util.Iterator public final DiskLruCache.Snapshot next() { if (!hasNext()) { throw new NoSuchElementException(); } DiskLruCache.Snapshot snapshot = this.nextSnapshot; this.removeSnapshot = snapshot; this.nextSnapshot = null; C14957gcv.e(snapshot); return snapshot; } @Override // java.util.Iterator public final void remove() { DiskLruCache.Snapshot snapshot = this.removeSnapshot; if (snapshot == null) { throw new IllegalStateException("remove() before next()".toString()); } try { this.this$0.remove(snapshot.key()); } catch (IOException unused) { } catch (Throwable th) { this.removeSnapshot = null; throw th; } this.removeSnapshot = null; } }