package okhttp3.n0.http1;

import java.util.ArrayList;
import java.util.Objects;
import kotlin.Metadata;
import kotlin.jvm.internal.o;
import kotlin.text.j;
import kotlinx.serialization.json.internal.AbstractJsonLexerKt;
import okhttp3.Headers;
import okio.BufferedSource;

/* JADX INFO: renamed from: y.n0.i.a, reason: from Kotlin metadata */
/* JADX INFO: loaded from: classes2.dex */
@Metadata(d1 = {"\u0000(\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\t\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000e\n\u0002\b\u0002\u0018\u0000 \r2\u00020\u0001:\u0001\rB\r\u0012\u0006\u0010\u0002\u001a\u00020\u0003¢\u0006\u0002\u0010\u0004J\u0006\u0010\t\u001a\u00020\nJ\u0006\u0010\u000b\u001a\u00020\fR\u000e\u0010\u0005\u001a\u00020\u0006X\u0082\u000e¢\u0006\u0002\n\u0000R\u0011\u0010\u0002\u001a\u00020\u0003¢\u0006\b\n\u0000\u001a\u0004\b\u0007\u0010\b¨\u0006\u000e"}, d2 = {"Lokhttp3/internal/http1/HeadersReader;", "", "source", "Lokio/BufferedSource;", "(Lokio/BufferedSource;)V", "headerLimit", "", "getSource", "()Lokio/BufferedSource;", "readHeaders", "Lokhttp3/Headers;", "readLine", "", "Companion", "okhttp"}, k = 1, mv = {1, 6, 0}, xi = 48)
public final class HeadersReader {
    public final BufferedSource a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public long f9839b;

    public HeadersReader(BufferedSource bufferedSource) {
        o.f(bufferedSource, "source");
        this.a = bufferedSource;
        this.f9839b = 262144L;
    }

    public final Headers a() {
        ArrayList arrayList = new ArrayList(20);
        while (true) {
            String strB = b();
            if (strB.length() == 0) {
                Object[] array = arrayList.toArray(new String[0]);
                Objects.requireNonNull(array, "null cannot be cast to non-null type kotlin.Array<T of kotlin.collections.ArraysKt__ArraysJVMKt.toTypedArray>");
                return new Headers((String[]) array, null);
            }
            o.f(strB, "line");
            int iM = j.m(strB, AbstractJsonLexerKt.COLON, 1, false, 4);
            if (iM != -1) {
                String strSubstring = strB.substring(0, iM);
                o.e(strSubstring, "this as java.lang.String…ing(startIndex, endIndex)");
                strB = strB.substring(iM + 1);
                o.e(strB, "this as java.lang.String).substring(startIndex)");
                o.f(strSubstring, "name");
                o.f(strB, "value");
                arrayList.add(strSubstring);
            } else {
                if (strB.charAt(0) == ':') {
                    strB = strB.substring(1);
                    o.e(strB, "this as java.lang.String).substring(startIndex)");
                }
                o.f("", "name");
                o.f(strB, "value");
                arrayList.add("");
            }
            arrayList.add(j.Y(strB).toString());
        }
    }

    public final String b() {
        String strI = this.a.i(this.f9839b);
        this.f9839b -= (long) strI.length();
        return strI;
    }
}
