package defpackage;

import java.io.IOException;
import java.net.ProtocolException;

/* JADX INFO: renamed from: ˈʞᵗˊ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C1018 extends AbstractC1004 {

    /* JADX INFO: renamed from: ˈᵲᵢ, reason: contains not printable characters */
    public final /* synthetic */ C2376 f4440;

    /* JADX INFO: renamed from: ᵯᵷʽ, reason: contains not printable characters */
    public long f4441;

    /* JADX INFO: renamed from: ᵶˇᵱ, reason: contains not printable characters */
    public boolean f4442;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public C1018(C2376 c2376, C1695 c1695) {
        super(c2376, c1695);
        this.f4440 = c2376;
        this.f4441 = -1L;
        this.f4442 = true;
    }

    @Override // java.io.Closeable, java.lang.AutoCloseable
    public final void close() {
        boolean zM3673;
        if (this.f4378) {
            return;
        }
        if (this.f4442) {
            try {
                zM3673 = AbstractC1190.m3673(this, 100);
            } catch (IOException unused) {
                zM3673 = false;
            }
            if (!zM3673) {
                this.f4440.f9300.mo8822();
                m3326(C2376.f9299);
            }
        }
        this.f4378 = true;
    }

    /* JADX WARN: Code restructure failed: missing block: B:45:0x00b9, code lost:
    
        if (r16.f4442 == false) goto L46;
     */
    @Override // defpackage.AbstractC1004, defpackage.InterfaceC3906
    /* JADX INFO: renamed from: ᵪᵹᵥᵻ */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final long mo1490(C4903 c4903, long j) throws IOException {
        byte bM10213;
        C2376 c2376 = this.f4440;
        ᵣˊˈᵪ r2 = c2376.f9301;
        if (this.f4378) {
            ᵕᵩʽᵲ.ᵪᵹᵥᵻ("closed");
            return 0L;
        }
        if (this.f4442) {
            long j2 = this.f4441;
            if (j2 == 0 || j2 == -1) {
                if (j2 != -1) {
                    ((C1978) r2.ᵔᵖᵹᵫ).mo5354(Long.MAX_VALUE);
                }
                try {
                    C1978 c1978 = (C1978) r2.ᵔᵖᵹᵫ;
                    C4903 c49032 = c1978.f7849;
                    c1978.mo5353(1L);
                    int i = 0;
                    while (true) {
                        int i2 = i + 1;
                        if (!c1978.request(i2)) {
                            break;
                        }
                        bM10213 = c49032.m10213(i);
                        if ((bM10213 < 48 || bM10213 > 57) && ((bM10213 < 97 || bM10213 > 102) && (bM10213 < 65 || bM10213 > 70))) {
                            break;
                        }
                        i = i2;
                    }
                    if (i == 0) {
                        ᵺᵘ.ᵱᵽʡᵚ(16);
                        throw new NumberFormatException("Expected leading [0-9a-fA-F] character but was 0x".concat(Integer.toString(bM10213, 16)));
                    }
                    this.f4441 = c49032.m10191();
                    String string = AbstractC3801.m8464(((C1978) r2.ᵔᵖᵹᵫ).mo5354(Long.MAX_VALUE)).toString();
                    if (this.f4441 < 0 || (string.length() > 0 && !AbstractC5498.m11136(string, ";", false))) {
                        throw new ProtocolException("expected chunk size and optional extensions but was \"" + this.f4441 + string + '\"');
                    }
                    if (this.f4441 == 0) {
                        this.f4442 = false;
                        m3326(c2376.f9302.m4697());
                    }
                } catch (NumberFormatException e) {
                    throw new ProtocolException(e.getMessage());
                }
            }
            long jMo1490 = super.mo1490(c4903, Math.min(8192L, this.f4441));
            if (jMo1490 != -1) {
                this.f4441 -= jMo1490;
                return jMo1490;
            }
            c2376.f9300.mo8822();
            ProtocolException protocolException = new ProtocolException("unexpected end of stream");
            m3326(C2376.f9299);
            throw protocolException;
        }
        return -1L;
    }
}
