package p447.p448.p455;

import java.io.Closeable;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import kotlin.jvm.internal.DefaultConstructorMarker;
import p138.p139.p143.p144.C2803;
import p402.InterfaceC6540;
import p402.p411.p413.C6635;
import p447.p448.C6943;
import p447.p448.p455.C7007;
import p461.C7103;
import p461.InterfaceC7106;

/* JADX INFO: renamed from: ސ.ޣ.އ.މ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
@InterfaceC6540
public final class C7041 implements Closeable {

    /* JADX INFO: renamed from: މ, reason: contains not printable characters */
    public static final Logger f20538;

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public final C7103 f20539;

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public int f20540;

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public boolean f20541;

    /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
    public final C7007.C7009 f20542;

    /* JADX INFO: renamed from: އ, reason: contains not printable characters */
    public final InterfaceC7106 f20543;

    /* JADX INFO: renamed from: ވ, reason: contains not printable characters */
    public final boolean f20544;

    /* JADX INFO: renamed from: ސ.ޣ.އ.މ$֏, reason: contains not printable characters */
    public static final class C7042 {
        public C7042() {
        }

        public /* synthetic */ C7042(DefaultConstructorMarker defaultConstructorMarker) {
        }
    }

    static {
        new C7042(null);
        f20538 = Logger.getLogger(C7010.class.getName());
    }

    public C7041(InterfaceC7106 interfaceC7106, boolean z) {
        if (interfaceC7106 == null) {
            C6635.m9824("sink");
            throw null;
        }
        this.f20543 = interfaceC7106;
        this.f20544 = z;
        C7103 c7103 = new C7103();
        this.f20539 = c7103;
        this.f20540 = 16384;
        this.f20542 = new C7007.C7009(0, false, c7103, 3, null);
    }

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

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

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final synchronized void m10344() {
        if (this.f20541) {
            throw new IOException("closed");
        }
        if (this.f20544) {
            if (f20538.isLoggable(Level.FINE)) {
                f20538.fine(C6943.m10156(">> CONNECTION " + C7010.f20411.mo10451(), new Object[0]));
            }
            this.f20543.mo10422(C7010.f20411);
            this.f20543.flush();
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m10345(int i, int i2, int i3, int i4) {
        if (f20538.isLoggable(Level.FINE)) {
            f20538.fine(C7010.f20415.m10294(false, i, i2, i3, i4));
        }
        if (!(i2 <= this.f20540)) {
            StringBuilder sbM4889 = C2803.m4889("FRAME_SIZE_ERROR length > ");
            sbM4889.append(this.f20540);
            sbM4889.append(": ");
            sbM4889.append(i2);
            throw new IllegalArgumentException(sbM4889.toString().toString());
        }
        if (!((((int) 2147483648L) & i) == 0)) {
            throw new IllegalArgumentException(C2803.m4871("reserved bit set: ", i).toString());
        }
        C6943.m10166(this.f20543, i2);
        this.f20543.writeByte(i3 & 255);
        this.f20543.writeByte(i4 & 255);
        this.f20543.writeInt(i & Integer.MAX_VALUE);
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final synchronized void m10346(int i, int i2, List<C7005> list) {
        if (list == null) {
            C6635.m9824("requestHeaders");
            throw null;
        }
        if (this.f20541) {
            throw new IOException("closed");
        }
        this.f20542.m10291(list);
        long j = this.f20539.f20630;
        int iMin = (int) Math.min(((long) this.f20540) - 4, j);
        long j2 = iMin;
        m10345(i, iMin + 4, 5, j == j2 ? 4 : 0);
        this.f20543.writeInt(i2 & Integer.MAX_VALUE);
        this.f20543.mo10205(this.f20539, j2);
        if (j > j2) {
            m10354(i, j - j2);
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final synchronized void m10347(int i, long j) {
        if (this.f20541) {
            throw new IOException("closed");
        }
        if (!(j != 0 && j <= 2147483647L)) {
            throw new IllegalArgumentException(("windowSizeIncrement == 0 || windowSizeIncrement > 0x7fffffffL: " + j).toString());
        }
        m10345(i, 4, 8, 0);
        this.f20543.writeInt((int) j);
        this.f20543.flush();
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final synchronized void m10348(int i, EnumC7003 enumC7003) {
        if (enumC7003 == null) {
            C6635.m9824("errorCode");
            throw null;
        }
        if (this.f20541) {
            throw new IOException("closed");
        }
        if (!(enumC7003.f20380 != -1)) {
            throw new IllegalArgumentException("Failed requirement.".toString());
        }
        m10345(i, 4, 3, 0);
        this.f20543.writeInt(enumC7003.f20380);
        this.f20543.flush();
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final synchronized void m10349(int i, EnumC7003 enumC7003, byte[] bArr) {
        if (enumC7003 == null) {
            C6635.m9824("errorCode");
            throw null;
        }
        if (bArr == null) {
            C6635.m9824("debugData");
            throw null;
        }
        if (this.f20541) {
            throw new IOException("closed");
        }
        if (!(enumC7003.f20380 != -1)) {
            throw new IllegalArgumentException("errorCode.httpCode == -1".toString());
        }
        m10345(0, bArr.length + 8, 7, 0);
        this.f20543.writeInt(i);
        this.f20543.writeInt(enumC7003.f20380);
        if (!(bArr.length == 0)) {
            this.f20543.write(bArr);
        }
        this.f20543.flush();
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final synchronized void m10350(C7048 c7048) {
        if (c7048 == null) {
            C6635.m9824("peerSettings");
            throw null;
        }
        if (this.f20541) {
            throw new IOException("closed");
        }
        int i = this.f20540;
        if ((c7048.f20553 & 32) != 0) {
            i = c7048.f20554[5];
        }
        this.f20540 = i;
        if (((c7048.f20553 & 2) != 0 ? c7048.f20554[1] : -1) != -1) {
            C7007.C7009 c7009 = this.f20542;
            int i2 = (c7048.f20553 & 2) != 0 ? c7048.f20554[1] : -1;
            c7009.f20408 = i2;
            int iMin = Math.min(i2, 16384);
            int i3 = c7009.f20403;
            if (i3 != iMin) {
                if (iMin < i3) {
                    c7009.f20401 = Math.min(c7009.f20401, iMin);
                }
                c7009.f20402 = true;
                c7009.f20403 = iMin;
                int i4 = c7009.f20407;
                if (iMin < i4) {
                    if (iMin == 0) {
                        c7009.m10289();
                    } else {
                        c7009.m10288(i4 - iMin);
                    }
                }
            }
        }
        m10345(0, 0, 4, 1);
        this.f20543.flush();
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final synchronized void m10351(boolean z, int i, int i2) {
        if (this.f20541) {
            throw new IOException("closed");
        }
        m10345(0, 8, 6, z ? 1 : 0);
        this.f20543.writeInt(i);
        this.f20543.writeInt(i2);
        this.f20543.flush();
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final synchronized void m10352(boolean z, int i, List<C7005> list) {
        if (list == null) {
            C6635.m9824("headerBlock");
            throw null;
        }
        if (this.f20541) {
            throw new IOException("closed");
        }
        this.f20542.m10291(list);
        long j = this.f20539.f20630;
        long jMin = Math.min(this.f20540, j);
        int i2 = j == jMin ? 4 : 0;
        if (z) {
            i2 |= 1;
        }
        m10345(i, (int) jMin, 1, i2);
        this.f20543.mo10205(this.f20539, jMin);
        if (j > jMin) {
            m10354(i, j - jMin);
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final synchronized void m10353(boolean z, int i, C7103 c7103, int i2) {
        if (this.f20541) {
            throw new IOException("closed");
        }
        m10345(i, i2, 0, z ? 1 : 0);
        if (i2 > 0) {
            InterfaceC7106 interfaceC7106 = this.f20543;
            if (c7103 == null) {
                C6635.m9822();
                throw null;
            }
            interfaceC7106.mo10205(c7103, i2);
        }
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final void m10354(int i, long j) {
        while (j > 0) {
            long jMin = Math.min(this.f20540, j);
            j -= jMin;
            m10345(i, (int) jMin, 9, j == 0 ? 4 : 0);
            this.f20543.mo10205(this.f20539, jMin);
        }
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final synchronized void m10355(C7048 c7048) {
        if (c7048 == null) {
            C6635.m9824("settings");
            throw null;
        }
        if (this.f20541) {
            throw new IOException("closed");
        }
        m10345(0, Integer.bitCount(c7048.f20553) * 6, 4, 0);
        int i = 0;
        while (i < 10) {
            boolean z = true;
            if (((1 << i) & c7048.f20553) == 0) {
                z = false;
            }
            if (z) {
                this.f20543.writeShort(i != 4 ? i != 7 ? i : 4 : 3);
                this.f20543.writeInt(c7048.f20554[i]);
            }
            i++;
        }
        this.f20543.flush();
    }
}
