package defpackage;

import java.io.IOException;
import java.util.ArrayList;

/* JADX INFO: renamed from: ᵷˏᵸ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C4889 {

    /* JADX INFO: renamed from: ˊᵫᵗ, reason: contains not printable characters */
    public int f18609;

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public long f18610;

    /* JADX INFO: renamed from: ᵵᵽ, reason: contains not printable characters */
    public int f18613;

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public final C1978 f18614;

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public int f18612 = 4096;

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public final ArrayList f18608 = new ArrayList();

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public C5511[] f18611 = new C5511[8];

    /* JADX INFO: renamed from: ᵻˈᵦʼ, reason: contains not printable characters */
    public int f18615 = 7;

    public C4889(C4617 c4617) {
        this.f18614 = new C1978(c4617);
    }

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public final int m10154(int i) {
        int i2;
        int i3 = 0;
        if (i > 0) {
            int length = this.f18611.length;
            while (true) {
                length--;
                i2 = this.f18615;
                if (length < i2 || i <= 0) {
                    break;
                }
                int i4 = this.f18611[length].f20816;
                i -= i4;
                this.f18609 -= i4;
                this.f18613--;
                i3++;
            }
            C5511[] c5511Arr = this.f18611;
            System.arraycopy(c5511Arr, i2 + 1, c5511Arr, i2 + 1 + i3, this.f18613);
            this.f18615 += i3;
        }
        return i3;
    }

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public final C1054 m10155(int i) throws IOException {
        if (i >= 0) {
            C5511[] c5511Arr = AbstractC4640.f17639;
            if (i <= c5511Arr.length - 1) {
                return c5511Arr[i].f20817;
            }
        }
        int length = this.f18615 + 1 + (i - AbstractC4640.f17639.length);
        if (length >= 0) {
            C5511[] c5511Arr2 = this.f18611;
            if (length < c5511Arr2.length) {
                return c5511Arr2[length].f20817;
            }
        }
        throw new IOException("Header index too large " + (i + 1));
    }

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public final C1054 m10156() {
        C1978 c1978 = this.f18614;
        byte b = c1978.readByte();
        byte[] bArr = AbstractC1701.f6716;
        int i = b & 255;
        int i2 = 0;
        boolean z = (b & 128) == 128;
        long jM10159 = m10159(i, 127);
        if (this.f18610 + jM10159 > 262144) {
            C1685.m4568("header byte count limit of 262144 exceeded");
            return null;
        }
        if (!z) {
            return c1978.mo5343(jM10159);
        }
        C4903 c4903 = new C4903();
        C3673 c3673 = AbstractC3793.f14405;
        C3673 c36732 = c3673;
        int i3 = 0;
        for (long j = 0; j < jM10159; j++) {
            byte b2 = c1978.readByte();
            byte[] bArr2 = AbstractC1701.f6716;
            i2 = (i2 << 8) | (b2 & 255);
            i3 += 8;
            while (i3 >= 8) {
                c36732 = ((C3673[]) c36732.f13946)[(i2 >>> (i3 - 8)) & 255];
                if (((C3673[]) c36732.f13946) == null) {
                    c4903.m10209(c36732.f13945);
                    i3 -= c36732.f13947;
                    c36732 = c3673;
                } else {
                    i3 -= 8;
                }
            }
        }
        while (i3 > 0) {
            C3673 c36733 = ((C3673[]) c36732.f13946)[(i2 << (8 - i3)) & 255];
            C3673[] c3673Arr = (C3673[]) c36733.f13946;
            int i4 = c36733.f13947;
            if (c3673Arr != null || i4 > i3) {
                break;
            }
            c4903.m10209(c36733.f13945);
            i3 -= i4;
            c36732 = c3673;
        }
        return c4903.mo5343(c4903.f18672);
    }

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public final void m10157(C5511 c5511) {
        this.f18608.add(c5511);
        long jMo3458 = this.f18610 + ((long) (c5511.f20815.mo3458() + c5511.f20817.mo3458()));
        this.f18610 = jMo3458;
        if (jMo3458 <= 262144) {
            return;
        }
        C1685.m4568("header byte count limit of 262144 exceeded");
    }

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public final void m10158(C5511 c5511) {
        m10157(c5511);
        int i = c5511.f20816;
        int i2 = this.f18612;
        if (i > i2) {
            AbstractC3761.m8429(this.f18611, null);
            this.f18615 = this.f18611.length - 1;
            this.f18613 = 0;
            this.f18609 = 0;
            return;
        }
        m10154((this.f18609 + i) - i2);
        int i3 = this.f18613 + 1;
        C5511[] c5511Arr = this.f18611;
        if (i3 > c5511Arr.length) {
            C5511[] c5511Arr2 = new C5511[c5511Arr.length * 2];
            System.arraycopy(c5511Arr, 0, c5511Arr2, c5511Arr.length, c5511Arr.length);
            this.f18615 = this.f18611.length - 1;
            this.f18611 = c5511Arr2;
        }
        int i4 = this.f18615;
        this.f18615 = i4 - 1;
        this.f18611[i4] = c5511;
        this.f18613++;
        this.f18609 += i;
    }

    /* JADX INFO: renamed from: ᵻˈᵦʼ, reason: contains not printable characters */
    public final int m10159(int i, int i2) {
        int i3 = i & i2;
        if (i3 < i2) {
            return i3;
        }
        long j = i2;
        int i4 = 0;
        int i5 = 0;
        while (i4 != 5) {
            byte b = this.f18614.readByte();
            byte[] bArr = AbstractC1701.f6716;
            i4++;
            long j2 = ((long) (b & 127)) << i5;
            if (j2 > 2147483647L - j) {
                C1685.m4568("HPACK integer overflow");
                return 0;
            }
            j += j2;
            if ((b & 128) == 0) {
                return (int) j;
            }
            i5 += 7;
        }
        C1685.m4568("HPACK integer overflow");
        return 0;
    }
}
