package com.google.android.gms.internal.ads;

import java.io.Closeable;
import java.io.EOFException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.NoSuchElementException;

/* JADX INFO: loaded from: classes2.dex */
public abstract class ag2 implements Iterator, Closeable, fd {

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public static final id f8695g = new id("eof ", 1);

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public cd f8696a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public k40 f8697b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public ed f8698c = null;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public long f8699d = 0;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public long f8700e = 0;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final ArrayList f8701f = new ArrayList();

    static {
        rb.q(ag2.class);
    }

    @Override // java.io.Closeable, java.lang.AutoCloseable
    public void close() {
    }

    @Override // java.util.Iterator
    /* JADX INFO: renamed from: g, reason: merged with bridge method [inline-methods] */
    public final ed next() {
        ed edVarA;
        ed edVar = this.f8698c;
        if (edVar != null && edVar != f8695g) {
            this.f8698c = null;
            return edVar;
        }
        k40 k40Var = this.f8697b;
        if (k40Var == null || this.f8699d >= this.f8700e) {
            this.f8698c = f8695g;
            throw new NoSuchElementException();
        }
        try {
            synchronized (k40Var) {
                this.f8697b.f13090a.position((int) this.f8699d);
                edVarA = ((bd) this.f8696a).a(this.f8697b, this);
                this.f8699d = this.f8697b.g();
            }
            return edVarA;
        } catch (EOFException unused) {
            throw new NoSuchElementException();
        } catch (IOException unused2) {
            throw new NoSuchElementException();
        }
    }

    @Override // java.util.Iterator
    public final boolean hasNext() {
        ed edVar = this.f8698c;
        id idVar = f8695g;
        if (edVar == idVar) {
            return false;
        }
        if (edVar != null) {
            return true;
        }
        try {
            this.f8698c = next();
            return true;
        } catch (NoSuchElementException unused) {
            this.f8698c = idVar;
            return false;
        }
    }

    @Override // java.util.Iterator
    public final void remove() {
        throw new UnsupportedOperationException();
    }

    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append("[");
        int i10 = 0;
        while (true) {
            ArrayList arrayList = this.f8701f;
            if (i10 >= arrayList.size()) {
                sb.append("]");
                return sb.toString();
            }
            if (i10 > 0) {
                sb.append(";");
            }
            sb.append(((ed) arrayList.get(i10)).toString());
            i10++;
        }
    }
}
