package okhttp3.n0.http;

import java.net.ProtocolException;
import kotlin.Metadata;
import kotlin.jvm.internal.o;
import kotlin.text.j;
import okhttp3.Protocol;

/* JADX INFO: renamed from: y.n0.h.j, reason: from Kotlin metadata */
/* JADX INFO: loaded from: classes2.dex */
@Metadata(d1 = {"\u0000\u001e\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\b\n\u0000\n\u0002\u0010\u000e\n\u0002\b\u0004\u0018\u0000 \n2\u00020\u0001:\u0001\nB\u001d\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\u0006\u0010\u0004\u001a\u00020\u0005\u0012\u0006\u0010\u0006\u001a\u00020\u0007¢\u0006\u0002\u0010\bJ\b\u0010\t\u001a\u00020\u0007H\u0016R\u0010\u0010\u0004\u001a\u00020\u00058\u0006X\u0087\u0004¢\u0006\u0002\n\u0000R\u0010\u0010\u0006\u001a\u00020\u00078\u0006X\u0087\u0004¢\u0006\u0002\n\u0000R\u0010\u0010\u0002\u001a\u00020\u00038\u0006X\u0087\u0004¢\u0006\u0002\n\u0000¨\u0006\u000b"}, d2 = {"Lokhttp3/internal/http/StatusLine;", "", "protocol", "Lokhttp3/Protocol;", "code", "", "message", "", "(Lokhttp3/Protocol;ILjava/lang/String;)V", "toString", "Companion", "okhttp"}, k = 1, mv = {1, 6, 0}, xi = 48)
public final class StatusLine {
    public final Protocol a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final int f9837b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final String f9838c;

    public StatusLine(Protocol protocol, int i2, String str) {
        o.f(protocol, "protocol");
        o.f(str, "message");
        this.a = protocol;
        this.f9837b = i2;
        this.f9838c = str;
    }

    public static final StatusLine a(String str) throws ProtocolException {
        String strSubstring;
        Protocol protocol = Protocol.HTTP_1_0;
        o.f(str, "statusLine");
        int i2 = 9;
        if (j.M(str, "HTTP/1.", false, 2)) {
            if (str.length() < 9 || str.charAt(8) != ' ') {
                throw new ProtocolException(o.l("Unexpected status line: ", str));
            }
            int iCharAt = str.charAt(7) - '0';
            if (iCharAt != 0) {
                if (iCharAt != 1) {
                    throw new ProtocolException(o.l("Unexpected status line: ", str));
                }
                protocol = Protocol.HTTP_1_1;
            }
        } else {
            if (!j.M(str, "ICY ", false, 2)) {
                throw new ProtocolException(o.l("Unexpected status line: ", str));
            }
            i2 = 4;
        }
        int i3 = i2 + 3;
        if (str.length() < i3) {
            throw new ProtocolException(o.l("Unexpected status line: ", str));
        }
        try {
            String strSubstring2 = str.substring(i2, i3);
            o.e(strSubstring2, "this as java.lang.String…ing(startIndex, endIndex)");
            int i4 = Integer.parseInt(strSubstring2);
            if (str.length() <= i3) {
                strSubstring = "";
            } else {
                if (str.charAt(i3) != ' ') {
                    throw new ProtocolException(o.l("Unexpected status line: ", str));
                }
                strSubstring = str.substring(i2 + 4);
                o.e(strSubstring, "this as java.lang.String).substring(startIndex)");
            }
            return new StatusLine(protocol, i4, strSubstring);
        } catch (NumberFormatException unused) {
            throw new ProtocolException(o.l("Unexpected status line: ", str));
        }
    }

    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(this.a == Protocol.HTTP_1_0 ? "HTTP/1.0" : "HTTP/1.1");
        sb.append(' ');
        sb.append(this.f9837b);
        sb.append(' ');
        sb.append(this.f9838c);
        String string = sb.toString();
        o.e(string, "StringBuilder().apply(builderAction).toString()");
        return string;
    }
}
