package defpackage;

import java.io.Closeable;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.logging.Level;
import java.util.logging.Logger;

/* renamed from: ᵲⁱ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C4537 implements Closeable {

    /* renamed from: ᵡⁱᵥ, reason: contains not printable characters */
    public static final Logger f16871 = Logger.getLogger(AbstractC5398.class.getName());

    /* renamed from: ᵢˇᵭ, reason: contains not printable characters */
    public final C0963 f16872;

    /* renamed from: ᵤᵙᵷ, reason: contains not printable characters */
    public final C0947 f16873;

    /* renamed from: ᵧᵾˀˈ, reason: contains not printable characters */
    public final InterfaceC3656 f16874;

    /* renamed from: ᵾᵬ, reason: contains not printable characters */
    public boolean f16875;

    /* renamed from: ᵿʗᵝʽ, reason: contains not printable characters */
    public int f16876;

    public C4537(InterfaceC3656 interfaceC3656) {
        this.f16874 = interfaceC3656;
        C0963 c0963 = new C0963();
        this.f16872 = c0963;
        this.f16876 = 16384;
        this.f16873 = new C0947(c0963);
    }

    @Override // java.io.Closeable, java.lang.AutoCloseable
    public final void close() {
        synchronized (this) {
            this.f16875 = true;
            this.f16874.close();
        }
    }

    public final void flush() {
        synchronized (this) {
            if (this.f16875) {
                throw new IOException("closed");
            }
            this.f16874.flush();
        }
    }

    /* renamed from: ˊᵸˊ, reason: contains not printable characters */
    public final void m9639(long j, int i) {
        synchronized (this) {
            try {
                if (this.f16875) {
                    throw new IOException("closed");
                }
                if (j == 0 || j > 2147483647L) {
                    throw new IllegalArgumentException(("windowSizeIncrement == 0 || windowSizeIncrement > 0x7fffffffL: " + j).toString());
                }
                Logger logger = f16871;
                if (logger.isLoggable(Level.FINE)) {
                    logger.fine(AbstractC5398.m11055(i, 4, j, false));
                }
                m9640(i, 4, 8, 0);
                this.f16874.writeInt((int) j);
                this.f16874.flush();
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    /* renamed from: ˌʾˀ, reason: contains not printable characters */
    public final void m9640(int i, int i2, int i3, int i4) {
        if (i3 != 8) {
            Level level = Level.FINE;
            Logger logger = f16871;
            if (logger.isLoggable(level)) {
                logger.fine(AbstractC5398.m11057(false, i, i2, i3, i4));
            }
        }
        if (i2 > this.f16876) {
            throw new IllegalArgumentException(("FRAME_SIZE_ERROR length > " + this.f16876 + ": " + i2).toString());
        }
        if ((Integer.MIN_VALUE & i) != 0) {
            ᵹˉᵞ.ᵸˑ(AbstractC2990.m7313(i, "reserved bit set: "));
            return;
        }
        byte[] bArr = AbstractC1348.f5567;
        InterfaceC3656 interfaceC3656 = this.f16874;
        interfaceC3656.writeByte((i2 >>> 16) & 255);
        interfaceC3656.writeByte((i2 >>> 8) & 255);
        interfaceC3656.writeByte(i2 & 255);
        interfaceC3656.writeByte(i3 & 255);
        interfaceC3656.writeByte(i4 & 255);
        interfaceC3656.writeInt(i & Integer.MAX_VALUE);
    }

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public final void m9641(boolean z, int i, C0963 c0963, int i2) {
        synchronized (this) {
            if (this.f16875) {
                throw new IOException("closed");
            }
            m9640(i, i2, 0, z ? 1 : 0);
            if (i2 > 0) {
                this.f16874.mo2377(c0963, i2);
            }
        }
    }

    /* renamed from: ˑᵥˁ, reason: contains not printable characters */
    public final void m9642(C2985 c2985) {
        synchronized (this) {
            try {
                if (this.f16875) {
                    throw new IOException("closed");
                }
                m9640(0, Integer.bitCount(c2985.f11531) * 6, 4, 0);
                for (int i = 0; i < 10; i++) {
                    boolean z = true;
                    if (((1 << i) & c2985.f11531) == 0) {
                        z = false;
                    }
                    if (z) {
                        this.f16874.writeShort(i);
                        this.f16874.writeInt(c2985.f11532[i]);
                    }
                }
                this.f16874.flush();
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    /* renamed from: ᵞʡ, reason: contains not printable characters */
    public final void m9643(byte[] bArr, int i, int i2) {
        synchronized (this) {
            if (this.f16875) {
                throw new IOException("closed");
            }
            if (AbstractC1327.m4088(i2) == -1) {
                throw new IllegalArgumentException("errorCode.httpCode == -1");
            }
            m9640(0, bArr.length + 8, 7, 0);
            this.f16874.writeInt(i);
            this.f16874.writeInt(AbstractC1327.m4088(i2));
            if (bArr.length != 0) {
                this.f16874.write(bArr);
            }
            this.f16874.flush();
        }
    }

    /* renamed from: ᵡˎ, reason: contains not printable characters */
    public final void m9644(int i, int i2) {
        synchronized (this) {
            if (this.f16875) {
                throw new IOException("closed");
            }
            if (AbstractC1327.m4088(i2) == -1) {
                throw new IllegalArgumentException("Failed requirement.");
            }
            m9640(i, 4, 3, 0);
            this.f16874.writeInt(AbstractC1327.m4088(i2));
            this.f16874.flush();
        }
    }

    /* renamed from: ᵡⁱᵥ, reason: contains not printable characters */
    public final void m9645(int i, int i2, boolean z) {
        synchronized (this) {
            if (this.f16875) {
                throw new IOException("closed");
            }
            m9640(0, 8, 6, z ? 1 : 0);
            this.f16874.writeInt(i);
            this.f16874.writeInt(i2);
            this.f16874.flush();
        }
    }

    /* renamed from: ᵢˇᵭ, reason: contains not printable characters */
    public final void m9646(boolean z, int i, ArrayList arrayList) {
        synchronized (this) {
            if (this.f16875) {
                throw new IOException("closed");
            }
            this.f16873.m3203(arrayList);
            long j = this.f16872.f4314;
            long jMin = Math.min(this.f16876, j);
            int i2 = j == jMin ? 4 : 0;
            if (z) {
                i2 |= 1;
            }
            m9640(i, (int) jMin, 1, i2);
            this.f16874.mo2377(this.f16872, jMin);
            if (j > jMin) {
                long j2 = j - jMin;
                while (j2 > 0) {
                    long jMin2 = Math.min(this.f16876, j2);
                    j2 -= jMin2;
                    m9640(i, (int) jMin2, 9, j2 == 0 ? 4 : 0);
                    this.f16874.mo2377(this.f16872, jMin2);
                }
            }
        }
    }

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final void m9647(C2985 c2985) {
        synchronized (this) {
            try {
                if (this.f16875) {
                    throw new IOException("closed");
                }
                int i = this.f16876;
                int i2 = c2985.f11531;
                if ((i2 & 32) != 0) {
                    i = c2985.f11532[5];
                }
                this.f16876 = i;
                if (((i2 & 2) != 0 ? c2985.f11532[1] : -1) != -1) {
                    C0947 c0947 = this.f16873;
                    int iMin = Math.min((i2 & 2) != 0 ? c2985.f11532[1] : -1, 16384);
                    int i3 = c0947.f4263;
                    if (i3 != iMin) {
                        if (iMin < i3) {
                            c0947.f4261 = Math.min(c0947.f4261, iMin);
                        }
                        c0947.f4259 = true;
                        c0947.f4263 = iMin;
                        int i4 = c0947.f4262;
                        if (iMin < i4) {
                            if (iMin == 0) {
                                C1162[] c1162Arr = c0947.f4256;
                                Arrays.fill(c1162Arr, 0, c1162Arr.length, (Object) null);
                                c0947.f4258 = c0947.f4256.length - 1;
                                c0947.f4257 = 0;
                                c0947.f4262 = 0;
                            } else {
                                c0947.m3201(i4 - iMin);
                            }
                        }
                    }
                }
                m9640(0, 0, 4, 1);
                this.f16874.flush();
            } catch (Throwable th) {
                throw th;
            }
        }
    }
}
