package 㿎.ሽ.㿎;

import com.google.android.material.progressindicator.BaseProgressIndicator;
import java.io.Closeable;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import okhttp3.internal.http2.ErrorCode;
import ᨨ.AbstractC1483;
import ᨨ.C1492;
import 㿎.ሽ.C2540;
import 㿎.ሽ.㿎.C2608;

/* renamed from: 㿎.ሽ.㿎.ᨨ  reason: contains not printable characters */
/* compiled from: Http2Writer */
public final class C2607 implements Closeable {

    /* renamed from: 㿎  reason: contains not printable characters */
    public static final Logger f8776 = Logger.getLogger(C2590.class.getName());

    /* renamed from: ʬ  reason: contains not printable characters */
    public final boolean f8777;

    /* renamed from: ඓ  reason: contains not printable characters */
    public int f8778 = 16384;

    /* renamed from: ῲ  reason: contains not printable characters */
    public final AbstractC1483 f8779;

    /* renamed from: ⁱ  reason: contains not printable characters */
    public final C2608.C2609 f8780 = new C2608.C2609(this.f8782);

    /* renamed from: 㴹  reason: contains not printable characters */
    public boolean f8781;

    /* renamed from: 㸾  reason: contains not printable characters */
    public final C1492 f8782 = new C1492();

    public C2607(AbstractC1483 r1, boolean z) {
        this.f8779 = r1;
        this.f8777 = z;
    }

    @Override // java.io.Closeable, java.lang.AutoCloseable
    public synchronized void close() throws IOException {
        this.f8781 = true;
        this.f8779.close();
    }

    public synchronized void flush() throws IOException {
        if (!this.f8781) {
            this.f8779.flush();
        } else {
            throw new IOException("closed");
        }
    }

    /* renamed from: ᨨ  reason: contains not printable characters */
    public synchronized void m6848() throws IOException {
        if (this.f8781) {
            throw new IOException("closed");
        } else if (this.f8777) {
            if (f8776.isLoggable(Level.FINE)) {
                f8776.fine(C2540.m6642(">> CONNECTION %s", C2590.f8713.hex()));
            }
            this.f8779.write(C2590.f8713.toByteArray());
            this.f8779.flush();
        }
    }

    /* JADX WARN: Incorrect args count in method signature: (ZIILjava/util/List<L㿎/ሽ/㿎/K;>;)V */
    /* renamed from: ῲ  reason: contains not printable characters */
    public synchronized void m6851(boolean z, int i, List list) throws IOException {
        if (!this.f8781) {
            m6859(z, i, list);
        } else {
            throw new IOException("closed");
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public synchronized void m6857(C2615 r5) throws IOException {
        if (!this.f8781) {
            int i = this.f8778;
            if ((r5.f8823 & 32) != 0) {
                i = r5.f8822[5];
            }
            this.f8778 = i;
            int i2 = -1;
            if (((r5.f8823 & 2) != 0 ? r5.f8822[1] : -1) != -1) {
                C2608.C2609 r0 = this.f8780;
                if ((r5.f8823 & 2) != 0) {
                    i2 = r5.f8822[1];
                }
                r0.m6862(i2);
            }
            m6852(0, 0, (byte) 4, (byte) 1);
            this.f8779.flush();
        } else {
            throw new IOException("closed");
        }
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public synchronized void m6850(C2615 r7) throws IOException {
        if (!this.f8781) {
            m6852(0, Integer.bitCount(r7.f8823) * 6, (byte) 4, (byte) 0);
            int i = 0;
            while (i < 10) {
                boolean z = true;
                if (((1 << i) & r7.f8823) == 0) {
                    z = false;
                }
                if (z) {
                    this.f8779.writeShort(i == 4 ? 3 : i == 7 ? 4 : i);
                    this.f8779.writeInt(r7.f8822[i]);
                }
                i++;
            }
            this.f8779.flush();
        } else {
            throw new IOException("closed");
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public synchronized void m6853(int i, int i2, List<C2614> list) throws IOException {
        if (!this.f8781) {
            this.f8780.m6866(list);
            long j = this.f8782.f5529;
            int min = (int) Math.min((long) (this.f8778 - 4), j);
            long j2 = (long) min;
            int i3 = (j > j2 ? 1 : (j == j2 ? 0 : -1));
            m6852(i, min + 4, (byte) 5, i3 == 0 ? (byte) 4 : 0);
            this.f8779.writeInt(i2 & Integer.MAX_VALUE);
            this.f8779.m3692(this.f8782, j2);
            if (i3 > 0) {
                m6849(i, j - j2);
            }
        } else {
            throw new IOException("closed");
        }
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public final void m6849(int i, long j) throws IOException {
        while (j > 0) {
            int min = (int) Math.min((long) this.f8778, j);
            long j2 = (long) min;
            j -= j2;
            m6852(i, min, (byte) 9, j == 0 ? (byte) 4 : 0);
            this.f8779.m3692(this.f8782, j2);
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public synchronized void m6855(int i, ErrorCode errorCode) throws IOException {
        if (this.f8781) {
            throw new IOException("closed");
        } else if (errorCode.httpCode != -1) {
            m6852(i, 4, (byte) 3, (byte) 0);
            this.f8779.writeInt(errorCode.httpCode);
            this.f8779.flush();
        } else {
            throw new IllegalArgumentException();
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public synchronized void m6860(boolean z, int i, C1492 r5, int i2) throws IOException {
        if (!this.f8781) {
            m6852(i, i2, (byte) 0, z ? (byte) 1 : 0);
            if (i2 > 0) {
                this.f8779.m3692(r5, (long) i2);
            }
        } else {
            throw new IOException("closed");
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public synchronized void m6858(boolean z, int i, int i2) throws IOException {
        if (!this.f8781) {
            m6852(0, 8, (byte) 6, z ? (byte) 1 : 0);
            this.f8779.writeInt(i);
            this.f8779.writeInt(i2);
            this.f8779.flush();
        } else {
            throw new IOException("closed");
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public synchronized void m6856(int i, ErrorCode errorCode, byte[] bArr) throws IOException {
        if (this.f8781) {
            throw new IOException("closed");
        } else if (errorCode.httpCode != -1) {
            m6852(0, bArr.length + 8, (byte) 7, (byte) 0);
            this.f8779.writeInt(i);
            this.f8779.writeInt(errorCode.httpCode);
            if (bArr.length > 0) {
                this.f8779.write(bArr);
            }
            this.f8779.flush();
        } else {
            C2590.m6802("errorCode.httpCode == -1", new Object[0]);
            throw null;
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public synchronized void m6854(int i, long j) throws IOException {
        if (this.f8781) {
            throw new IOException("closed");
        } else if (j == 0 || j > 2147483647L) {
            C2590.m6802("windowSizeIncrement == 0 || windowSizeIncrement > 0x7fffffffL: %s", Long.valueOf(j));
            throw null;
        } else {
            m6852(i, 4, (byte) 8, (byte) 0);
            this.f8779.writeInt((int) j);
            this.f8779.flush();
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public void m6852(int i, int i2, byte b, byte b2) throws IOException {
        if (f8776.isLoggable(Level.FINE)) {
            f8776.fine(C2590.m6803(false, i, i2, b, b2));
        }
        int i3 = this.f8778;
        if (i2 > i3) {
            C2590.m6802("FRAME_SIZE_ERROR length > %d: %d", Integer.valueOf(i3), Integer.valueOf(i2));
            throw null;
        } else if ((Integer.MIN_VALUE & i) == 0) {
            AbstractC1483 r0 = this.f8779;
            r0.writeByte((i2 >>> 16) & BaseProgressIndicator.MAX_ALPHA);
            r0.writeByte((i2 >>> 8) & BaseProgressIndicator.MAX_ALPHA);
            r0.writeByte(i2 & BaseProgressIndicator.MAX_ALPHA);
            this.f8779.writeByte(b & 255);
            this.f8779.writeByte(b2 & 255);
            this.f8779.writeInt(i & Integer.MAX_VALUE);
        } else {
            C2590.m6802("reserved bit set: %s", Integer.valueOf(i));
            throw null;
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public void m6859(boolean z, int i, List<C2614> list) throws IOException {
        if (!this.f8781) {
            this.f8780.m6866(list);
            long j = this.f8782.f5529;
            int min = (int) Math.min((long) this.f8778, j);
            long j2 = (long) min;
            int i2 = (j > j2 ? 1 : (j == j2 ? 0 : -1));
            byte b = i2 == 0 ? (byte) 4 : 0;
            if (z) {
                b = (byte) (b | 1);
            }
            m6852(i, min, (byte) 1, b);
            this.f8779.m3692(this.f8782, j2);
            if (i2 > 0) {
                m6849(i, j - j2);
                return;
            }
            return;
        }
        throw new IOException("closed");
    }
}
