package p447.p448.p454;

import java.io.EOFException;
import java.io.IOException;
import java.net.ProtocolException;
import java.net.Proxy;
import java.net.Socket;
import java.util.concurrent.TimeUnit;
import kotlin.TypeCastException;
import kotlin.jvm.internal.DefaultConstructorMarker;
import p138.p139.p143.p144.C2803;
import p402.InterfaceC6540;
import p402.p411.p413.C6635;
import p402.p420.C6703;
import p447.AbstractC6930;
import p447.C6905;
import p447.C6908;
import p447.C6921;
import p447.C6926;
import p447.C6933;
import p447.InterfaceC6886;
import p447.p448.C6943;
import p447.p448.p452.C6968;
import p447.p448.p453.C6985;
import p447.p448.p453.C6991;
import p447.p448.p453.InterfaceC6984;
import p461.C7103;
import p461.C7112;
import p461.C7130;
import p461.InterfaceC7106;
import p461.InterfaceC7107;
import p461.InterfaceC7127;
import p461.InterfaceC7129;

/* JADX INFO: renamed from: ސ.ޣ.ކ.ؠ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
@InterfaceC6540
public final class C6995 implements InterfaceC6984 {

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

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final C6993 f20350;

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public C6905 f20351;

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public final C6921 f20352;

    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    public final C6968 f20353;

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

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

    /* JADX INFO: renamed from: ސ.ޣ.ކ.ؠ$֏, reason: contains not printable characters */
    public abstract class AbstractC6996 implements InterfaceC7129 {

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

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

        public AbstractC6996() {
            this.f20356 = new C7112(C6995.this.f20354.mo10277());
        }

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final void m10276() {
            C6995 c6995 = C6995.this;
            int i = c6995.f20349;
            if (i == 6) {
                return;
            }
            if (i == 5) {
                C6995.m10273(c6995, this.f20356);
                C6995.this.f20349 = 6;
            } else {
                StringBuilder sbM4889 = C2803.m4889("state: ");
                sbM4889.append(C6995.this.f20349);
                throw new IllegalStateException(sbM4889.toString());
            }
        }

        @Override // p461.InterfaceC7129
        /* JADX INFO: renamed from: ؠ */
        public long mo10207(C7103 c7103, long j) throws IOException {
            if (c7103 == null) {
                C6635.m9824("sink");
                throw null;
            }
            try {
                return C6995.this.f20354.mo10207(c7103, j);
            } catch (IOException e) {
                C6995.this.f20353.m10237();
                m10276();
                throw e;
            }
        }

        @Override // p461.InterfaceC7129
        /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
        public C7130 mo10277() {
            return this.f20356;
        }
    }

    /* JADX INFO: renamed from: ސ.ޣ.ކ.ؠ$ؠ, reason: contains not printable characters */
    public final class C6997 implements InterfaceC7127 {

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

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

        public C6997() {
            this.f20359 = new C7112(C6995.this.f20355.mo10278());
        }

        @Override // p461.InterfaceC7127, java.io.Closeable, java.lang.AutoCloseable
        public synchronized void close() {
            if (this.f20360) {
                return;
            }
            this.f20360 = true;
            C6995.this.f20355.mo10414("0\r\n\r\n");
            C6995.m10273(C6995.this, this.f20359);
            C6995.this.f20349 = 3;
        }

        @Override // p461.InterfaceC7127, java.io.Flushable
        public synchronized void flush() {
            if (this.f20360) {
                return;
            }
            C6995.this.f20355.flush();
        }

        @Override // p461.InterfaceC7127
        /* JADX INFO: renamed from: ֏ */
        public void mo10205(C7103 c7103, long j) {
            if (c7103 == null) {
                C6635.m9824("source");
                throw null;
            }
            if (!(!this.f20360)) {
                throw new IllegalStateException("closed".toString());
            }
            if (j == 0) {
                return;
            }
            C6995.this.f20355.mo10421(j);
            C6995.this.f20355.mo10414("\r\n");
            C6995.this.f20355.mo10205(c7103, j);
            C6995.this.f20355.mo10414("\r\n");
        }

        @Override // p461.InterfaceC7127
        /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
        public C7130 mo10278() {
            return this.f20359;
        }
    }

    /* JADX INFO: renamed from: ސ.ޣ.ކ.ؠ$ހ, reason: contains not printable characters */
    public final class C6998 extends AbstractC6996 {

        /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
        public long f20362;

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

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

        /* JADX INFO: renamed from: މ, reason: contains not printable characters */
        public final /* synthetic */ C6995 f20365;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C6998(C6995 c6995, C6908 c6908) {
            super();
            if (c6908 == null) {
                C6635.m9824("url");
                throw null;
            }
            this.f20365 = c6995;
            this.f20364 = c6908;
            this.f20362 = -1L;
            this.f20363 = true;
        }

        @Override // p461.InterfaceC7129, java.io.Closeable, java.lang.AutoCloseable
        public void close() {
            if (this.f20357) {
                return;
            }
            if (this.f20363 && !C6943.m10170(this, 100, TimeUnit.MILLISECONDS)) {
                this.f20365.f20353.m10237();
                m10276();
            }
            this.f20357 = true;
        }

        @Override // p447.p448.p454.C6995.AbstractC6996, p461.InterfaceC7129
        /* JADX INFO: renamed from: ؠ */
        public long mo10207(C7103 c7103, long j) throws IOException {
            if (c7103 == null) {
                C6635.m9824("sink");
                throw null;
            }
            boolean z = true;
            if (!(j >= 0)) {
                throw new IllegalArgumentException(C2803.m4874("byteCount < 0: ", j).toString());
            }
            if (!(!this.f20357)) {
                throw new IllegalStateException("closed".toString());
            }
            if (!this.f20363) {
                return -1L;
            }
            long j2 = this.f20362;
            if (j2 == 0 || j2 == -1) {
                if (this.f20362 != -1) {
                    this.f20365.f20354.mo10435();
                }
                try {
                    this.f20362 = this.f20365.f20354.mo10440();
                    String strMo10435 = this.f20365.f20354.mo10435();
                    if (strMo10435 == null) {
                        throw new TypeCastException("null cannot be cast to non-null type kotlin.CharSequence");
                    }
                    String string = C6703.m9900(strMo10435).toString();
                    if (this.f20362 >= 0) {
                        if (string.length() <= 0) {
                            z = false;
                        }
                        if (!z || C6703.m9899(string, ";", false, 2)) {
                            if (this.f20362 == 0) {
                                this.f20363 = false;
                                C6995 c6995 = this.f20365;
                                c6995.f20351 = c6995.f20350.m10271();
                                C6995 c69952 = this.f20365;
                                C6921 c6921 = c69952.f20352;
                                if (c6921 == null) {
                                    C6635.m9822();
                                    throw null;
                                }
                                InterfaceC6886 interfaceC6886 = c6921.f20067;
                                C6908 c6908 = this.f20364;
                                C6905 c6905 = c69952.f20351;
                                if (c6905 == null) {
                                    C6635.m9822();
                                    throw null;
                                }
                                C6985.m10260(interfaceC6886, c6908, c6905);
                                m10276();
                            }
                            if (!this.f20363) {
                                return -1L;
                            }
                        }
                    }
                    throw new ProtocolException("expected chunk size and optional extensions but was \"" + this.f20362 + string + '\"');
                } catch (NumberFormatException e) {
                    throw new ProtocolException(e.getMessage());
                }
            }
            long jMo10207 = super.mo10207(c7103, Math.min(j, this.f20362));
            if (jMo10207 != -1) {
                this.f20362 -= jMo10207;
                return jMo10207;
            }
            this.f20365.f20353.m10237();
            ProtocolException protocolException = new ProtocolException("unexpected end of stream");
            m10276();
            throw protocolException;
        }
    }

    /* JADX INFO: renamed from: ސ.ޣ.ކ.ؠ$ށ, reason: contains not printable characters */
    public static final class C6999 {
        public C6999() {
        }

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

    /* JADX INFO: renamed from: ސ.ޣ.ކ.ؠ$ނ, reason: contains not printable characters */
    public final class C7000 extends AbstractC6996 {

        /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
        public long f20366;

        public C7000(long j) {
            super();
            this.f20366 = j;
            if (j == 0) {
                m10276();
            }
        }

        @Override // p461.InterfaceC7129, java.io.Closeable, java.lang.AutoCloseable
        public void close() {
            if (this.f20357) {
                return;
            }
            if (this.f20366 != 0 && !C6943.m10170(this, 100, TimeUnit.MILLISECONDS)) {
                C6995.this.f20353.m10237();
                m10276();
            }
            this.f20357 = true;
        }

        @Override // p447.p448.p454.C6995.AbstractC6996, p461.InterfaceC7129
        /* JADX INFO: renamed from: ؠ */
        public long mo10207(C7103 c7103, long j) throws IOException {
            if (c7103 == null) {
                C6635.m9824("sink");
                throw null;
            }
            if (!(j >= 0)) {
                throw new IllegalArgumentException(C2803.m4874("byteCount < 0: ", j).toString());
            }
            if (!(!this.f20357)) {
                throw new IllegalStateException("closed".toString());
            }
            long j2 = this.f20366;
            if (j2 == 0) {
                return -1L;
            }
            long jMo10207 = super.mo10207(c7103, Math.min(j2, j));
            if (jMo10207 == -1) {
                C6995.this.f20353.m10237();
                ProtocolException protocolException = new ProtocolException("unexpected end of stream");
                m10276();
                throw protocolException;
            }
            long j3 = this.f20366 - jMo10207;
            this.f20366 = j3;
            if (j3 == 0) {
                m10276();
            }
            return jMo10207;
        }
    }

    /* JADX INFO: renamed from: ސ.ޣ.ކ.ؠ$ރ, reason: contains not printable characters */
    public final class C7001 implements InterfaceC7127 {

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

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

        public C7001() {
            this.f20368 = new C7112(C6995.this.f20355.mo10278());
        }

        @Override // p461.InterfaceC7127, java.io.Closeable, java.lang.AutoCloseable
        public void close() {
            if (this.f20369) {
                return;
            }
            this.f20369 = true;
            C6995.m10273(C6995.this, this.f20368);
            C6995.this.f20349 = 3;
        }

        @Override // p461.InterfaceC7127, java.io.Flushable
        public void flush() {
            if (this.f20369) {
                return;
            }
            C6995.this.f20355.flush();
        }

        @Override // p461.InterfaceC7127
        /* JADX INFO: renamed from: ֏ */
        public void mo10205(C7103 c7103, long j) {
            if (c7103 == null) {
                C6635.m9824("source");
                throw null;
            }
            if (!(!this.f20369)) {
                throw new IllegalStateException("closed".toString());
            }
            C6943.m10163(c7103.f20630, 0L, j);
            C6995.this.f20355.mo10205(c7103, j);
        }

        @Override // p461.InterfaceC7127
        /* JADX INFO: renamed from: ށ */
        public C7130 mo10278() {
            return this.f20368;
        }
    }

    /* JADX INFO: renamed from: ސ.ޣ.ކ.ؠ$ބ, reason: contains not printable characters */
    public final class C7002 extends AbstractC6996 {

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

        public C7002(C6995 c6995) {
            super();
        }

        @Override // p461.InterfaceC7129, java.io.Closeable, java.lang.AutoCloseable
        public void close() {
            if (this.f20357) {
                return;
            }
            if (!this.f20371) {
                m10276();
            }
            this.f20357 = true;
        }

        @Override // p447.p448.p454.C6995.AbstractC6996, p461.InterfaceC7129
        /* JADX INFO: renamed from: ؠ */
        public long mo10207(C7103 c7103, long j) throws IOException {
            if (c7103 == null) {
                C6635.m9824("sink");
                throw null;
            }
            if (!(j >= 0)) {
                throw new IllegalArgumentException(C2803.m4874("byteCount < 0: ", j).toString());
            }
            if (!(!this.f20357)) {
                throw new IllegalStateException("closed".toString());
            }
            if (this.f20371) {
                return -1L;
            }
            long jMo10207 = super.mo10207(c7103, j);
            if (jMo10207 != -1) {
                return jMo10207;
            }
            this.f20371 = true;
            m10276();
            return -1L;
        }
    }

    static {
        new C6999(null);
    }

    public C6995(C6921 c6921, C6968 c6968, InterfaceC7107 interfaceC7107, InterfaceC7106 interfaceC7106) {
        if (c6968 == null) {
            C6635.m9824("connection");
            throw null;
        }
        if (interfaceC7107 == null) {
            C6635.m9824("source");
            throw null;
        }
        if (interfaceC7106 == null) {
            C6635.m9824("sink");
            throw null;
        }
        this.f20352 = c6921;
        this.f20353 = c6968;
        this.f20354 = interfaceC7107;
        this.f20355 = interfaceC7106;
        this.f20350 = new C6993(this.f20354);
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static final /* synthetic */ void m10273(C6995 c6995, C7112 c7112) {
        if (c6995 == null) {
            throw null;
        }
        C7130 c7130 = c7112.f20640;
        C7130 c71302 = C7130.f20679;
        if (c71302 == null) {
            C6635.m9824("delegate");
            throw null;
        }
        c7112.f20640 = c71302;
        c7130.mo10458();
        c7130.mo10461();
    }

    @Override // p447.p448.p453.InterfaceC6984
    public void cancel() {
        Socket socket = this.f20353.f20283;
        if (socket != null) {
            C6943.m10165(socket);
        }
    }

    @Override // p447.p448.p453.InterfaceC6984
    /* JADX INFO: renamed from: ֏ */
    public long mo10250(C6933 c6933) {
        if (c6933 == null) {
            C6635.m9824("response");
            throw null;
        }
        if (!C6985.m10262(c6933)) {
            return 0L;
        }
        if (C6703.m9905("chunked", C6933.m10126(c6933, "Transfer-Encoding", null, 2), true)) {
            return -1L;
        }
        return C6943.m10155(c6933);
    }

    @Override // p447.p448.p453.InterfaceC6984
    /* JADX INFO: renamed from: ֏ */
    public C6933.C6934 mo10251(boolean z) {
        int i = this.f20349;
        boolean z2 = true;
        if (i != 1 && i != 3) {
            z2 = false;
        }
        if (!z2) {
            StringBuilder sbM4889 = C2803.m4889("state: ");
            sbM4889.append(this.f20349);
            throw new IllegalStateException(sbM4889.toString().toString());
        }
        try {
            C6991 c6991M10270 = C6991.f20343.m10270(this.f20350.m10272());
            C6933.C6934 c6934 = new C6933.C6934();
            c6934.m10130(c6991M10270.f20344);
            c6934.f20161 = c6991M10270.f20345;
            c6934.m10128(c6991M10270.f20346);
            c6934.m10129(this.f20350.m10271());
            if (z && c6991M10270.f20345 == 100) {
                return null;
            }
            if (c6991M10270.f20345 == 100) {
                this.f20349 = 3;
                return c6934;
            }
            this.f20349 = 4;
            return c6934;
        } catch (EOFException e) {
            throw new IOException(C2803.m4879("unexpected end of stream on ", this.f20353.f20299.f20176.f19900.m10087()), e);
        }
    }

    @Override // p447.p448.p453.InterfaceC6984
    /* JADX INFO: renamed from: ֏ */
    public InterfaceC7127 mo10252(C6926 c6926, long j) {
        if (c6926 == null) {
            C6635.m9824("request");
            throw null;
        }
        AbstractC6930 abstractC6930 = c6926.f20131;
        if (abstractC6930 != null && abstractC6930 == null) {
            throw null;
        }
        if (C6703.m9905("chunked", c6926.m10115("Transfer-Encoding"), true)) {
            if (this.f20349 == 1) {
                this.f20349 = 2;
                return new C6997();
            }
            StringBuilder sbM4889 = C2803.m4889("state: ");
            sbM4889.append(this.f20349);
            throw new IllegalStateException(sbM4889.toString().toString());
        }
        if (j == -1) {
            throw new IllegalStateException("Cannot stream a request body without chunked encoding or a known content length!");
        }
        if (this.f20349 == 1) {
            this.f20349 = 2;
            return new C7001();
        }
        StringBuilder sbM48892 = C2803.m4889("state: ");
        sbM48892.append(this.f20349);
        throw new IllegalStateException(sbM48892.toString().toString());
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final InterfaceC7129 m10274(long j) {
        if (this.f20349 == 4) {
            this.f20349 = 5;
            return new C7000(j);
        }
        StringBuilder sbM4889 = C2803.m4889("state: ");
        sbM4889.append(this.f20349);
        throw new IllegalStateException(sbM4889.toString().toString());
    }

    @Override // p447.p448.p453.InterfaceC6984
    /* JADX INFO: renamed from: ֏ */
    public void mo10253() {
        this.f20355.flush();
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m10275(C6905 c6905, String str) {
        if (c6905 == null) {
            C6635.m9824("headers");
            throw null;
        }
        if (str == null) {
            C6635.m9824("requestLine");
            throw null;
        }
        if (!(this.f20349 == 0)) {
            StringBuilder sbM4889 = C2803.m4889("state: ");
            sbM4889.append(this.f20349);
            throw new IllegalStateException(sbM4889.toString().toString());
        }
        this.f20355.mo10414(str).mo10414("\r\n");
        int size = c6905.size();
        for (int i = 0; i < size; i++) {
            this.f20355.mo10414(c6905.m10068(i)).mo10414(": ").mo10414(c6905.m10070(i)).mo10414("\r\n");
        }
        this.f20355.mo10414("\r\n");
        this.f20349 = 1;
    }

    @Override // p447.p448.p453.InterfaceC6984
    /* JADX INFO: renamed from: ֏ */
    public void mo10254(C6926 c6926) {
        if (c6926 == null) {
            C6635.m9824("request");
            throw null;
        }
        Proxy.Type type = this.f20353.f20299.f20177.type();
        C6635.m9823((Object) type, "connection.route().proxy.type()");
        StringBuilder sb = new StringBuilder();
        sb.append(c6926.f20129);
        sb.append(' ');
        if (!c6926.f20128.f20013 && type == Proxy.Type.HTTP) {
            sb.append(c6926.f20128);
        } else {
            C6908 c6908 = c6926.f20128;
            if (c6908 == null) {
                C6635.m9824("url");
                throw null;
            }
            String strM10081 = c6908.m10081();
            String strM10084 = c6908.m10084();
            if (strM10084 != null) {
                strM10081 = strM10081 + '?' + strM10084;
            }
            sb.append(strM10081);
        }
        sb.append(" HTTP/1.1");
        String string = sb.toString();
        C6635.m9823((Object) string, "StringBuilder().apply(builderAction).toString()");
        m10275(c6926.f20130, string);
    }

    @Override // p447.p448.p453.InterfaceC6984
    /* JADX INFO: renamed from: ؠ */
    public InterfaceC7129 mo10255(C6933 c6933) {
        if (c6933 == null) {
            C6635.m9824("response");
            throw null;
        }
        if (!C6985.m10262(c6933)) {
            return m10274(0L);
        }
        if (C6703.m9905("chunked", C6933.m10126(c6933, "Transfer-Encoding", null, 2), true)) {
            C6908 c6908 = c6933.f20146.f20128;
            if (this.f20349 == 4) {
                this.f20349 = 5;
                return new C6998(this, c6908);
            }
            StringBuilder sbM4889 = C2803.m4889("state: ");
            sbM4889.append(this.f20349);
            throw new IllegalStateException(sbM4889.toString().toString());
        }
        long jM10155 = C6943.m10155(c6933);
        if (jM10155 != -1) {
            return m10274(jM10155);
        }
        if (this.f20349 == 4) {
            this.f20349 = 5;
            this.f20353.m10237();
            return new C7002(this);
        }
        StringBuilder sbM48892 = C2803.m4889("state: ");
        sbM48892.append(this.f20349);
        throw new IllegalStateException(sbM48892.toString().toString());
    }

    @Override // p447.p448.p453.InterfaceC6984
    /* JADX INFO: renamed from: ؠ */
    public void mo10256() {
        this.f20355.flush();
    }

    @Override // p447.p448.p453.InterfaceC6984
    /* JADX INFO: renamed from: ހ */
    public C6968 mo10257() {
        return this.f20353;
    }
}
