package L4;

import A4.h;
import A4.i;
import K4.m;
import K4.o;
import K4.v;
import R4.C0184c;
import S4.d;
import X4.e;
import X4.u;
import e4.AbstractC0565i;
import e4.AbstractC0566j;
import java.io.Closeable;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.NoSuchElementException;
import java.util.TimeZone;
import java.util.concurrent.TimeUnit;
import r4.AbstractC0983h;

/* JADX INFO: loaded from: classes.dex */
public abstract class b {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final byte[] f2100a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final m f2101b = d.B(new String[0]);

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static final v f2102c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static final TimeZone f2103d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public static final h f2104e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public static final String f2105f;

    /* JADX WARN: Code restructure failed: missing block: B:79:0x015d, code lost:
    
        continue;
     */
    static {
        /*
            Method dump skipped, instruction units count: 469
            To view this dump change 'Code comments level' option to 'DEBUG'
        */
        throw new UnsupportedOperationException("Method not decompiled: L4.b.<clinit>():void");
    }

    public static final boolean a(o oVar, o oVar2) {
        AbstractC0983h.e("<this>", oVar);
        AbstractC0983h.e("other", oVar2);
        return AbstractC0983h.a(oVar.f1161d, oVar2.f1161d) && oVar.f1162e == oVar2.f1162e && AbstractC0983h.a(oVar.f1158a, oVar2.f1158a);
    }

    public static final void b(Closeable closeable) {
        AbstractC0983h.e("<this>", closeable);
        try {
            closeable.close();
        } catch (RuntimeException e2) {
            throw e2;
        } catch (Exception unused) {
        }
    }

    public static final void c(Socket socket) {
        AbstractC0983h.e("<this>", socket);
        try {
            socket.close();
        } catch (AssertionError e2) {
            throw e2;
        } catch (RuntimeException e6) {
            if (!AbstractC0983h.a(e6.getMessage(), "bio == null")) {
                throw e6;
            }
        } catch (Exception unused) {
        }
    }

    public static final int d(int i, int i5, String str, String str2) {
        while (i < i5) {
            int i6 = i + 1;
            if (i.J(str2, str.charAt(i))) {
                return i;
            }
            i = i6;
        }
        return i5;
    }

    public static final int e(String str, char c6, int i, int i5) {
        while (i < i5) {
            int i6 = i + 1;
            if (str.charAt(i) == c6) {
                return i;
            }
            i = i6;
        }
        return i5;
    }

    public static final boolean f(u uVar) {
        AbstractC0983h.e("timeUnit", TimeUnit.MILLISECONDS);
        try {
            return r(uVar, 100);
        } catch (IOException unused) {
            return false;
        }
    }

    public static final String g(String str, Object... objArr) {
        AbstractC0983h.e("format", str);
        Locale locale = Locale.US;
        Object[] objArrCopyOf = Arrays.copyOf(objArr, objArr.length);
        return String.format(locale, str, Arrays.copyOf(objArrCopyOf, objArrCopyOf.length));
    }

    public static final boolean h(String[] strArr, String[] strArr2, Comparator comparator) {
        AbstractC0983h.e("<this>", strArr);
        if (strArr.length != 0 && strArr2 != null && strArr2.length != 0) {
            int length = strArr.length;
            int i = 0;
            while (i < length) {
                String str = strArr[i];
                i++;
                int i5 = 0;
                while (true) {
                    if (i5 < strArr2.length) {
                        int i6 = i5 + 1;
                        try {
                            if (comparator.compare(str, strArr2[i5]) == 0) {
                                return true;
                            }
                            i5 = i6;
                        } catch (ArrayIndexOutOfBoundsException e2) {
                            throw new NoSuchElementException(e2.getMessage());
                        }
                    }
                }
            }
        }
        return false;
    }

    public static final long i(K4.u uVar) {
        String strA = uVar.p.a("Content-Length");
        if (strA == null) {
            return -1L;
        }
        try {
            return Long.parseLong(strA);
        } catch (NumberFormatException unused) {
            return -1L;
        }
    }

    public static final List j(Object... objArr) {
        AbstractC0983h.e("elements", objArr);
        Object[] objArr2 = (Object[]) objArr.clone();
        List listUnmodifiableList = Collections.unmodifiableList(AbstractC0566j.s(Arrays.copyOf(objArr2, objArr2.length)));
        AbstractC0983h.d("unmodifiableList(listOf(*elements.clone()))", listUnmodifiableList);
        return listUnmodifiableList;
    }

    public static final int k(String str) {
        int length = str.length();
        int i = 0;
        while (i < length) {
            int i5 = i + 1;
            char cCharAt = str.charAt(i);
            if (AbstractC0983h.f(cCharAt, 31) <= 0 || AbstractC0983h.f(cCharAt, 127) >= 0) {
                return i;
            }
            i = i5;
        }
        return -1;
    }

    public static final int l(int i, String str, int i5) {
        while (i < i5) {
            int i6 = i + 1;
            char cCharAt = str.charAt(i);
            if (cCharAt != '\t' && cCharAt != '\n' && cCharAt != '\f' && cCharAt != '\r' && cCharAt != ' ') {
                return i;
            }
            i = i6;
        }
        return i5;
    }

    public static final int m(int i, String str, int i5) {
        int i6 = i5 - 1;
        if (i <= i6) {
            while (true) {
                int i7 = i6 - 1;
                char cCharAt = str.charAt(i6);
                if (cCharAt != '\t' && cCharAt != '\n' && cCharAt != '\f' && cCharAt != '\r' && cCharAt != ' ') {
                    return i6 + 1;
                }
                if (i6 == i) {
                    break;
                }
                i6 = i7;
            }
        }
        return i;
    }

    public static final String[] n(String[] strArr, String[] strArr2, Comparator comparator) {
        AbstractC0983h.e("other", strArr2);
        ArrayList arrayList = new ArrayList();
        int length = strArr.length;
        int i = 0;
        while (i < length) {
            String str = strArr[i];
            i++;
            int length2 = strArr2.length;
            int i5 = 0;
            while (true) {
                if (i5 < length2) {
                    String str2 = strArr2[i5];
                    i5++;
                    if (comparator.compare(str, str2) == 0) {
                        arrayList.add(str);
                        break;
                    }
                }
            }
        }
        Object[] array = arrayList.toArray(new String[0]);
        if (array != null) {
            return (String[]) array;
        }
        throw new NullPointerException("null cannot be cast to non-null type kotlin.Array<T of kotlin.collections.ArraysKt__ArraysJVMKt.toTypedArray>");
    }

    public static final boolean o(String str) {
        AbstractC0983h.e("name", str);
        return str.equalsIgnoreCase("Authorization") || str.equalsIgnoreCase("Cookie") || str.equalsIgnoreCase("Proxy-Authorization") || str.equalsIgnoreCase("Set-Cookie");
    }

    public static final int p(char c6) {
        if ('0' <= c6 && c6 < ':') {
            return c6 - '0';
        }
        if ('a' <= c6 && c6 < 'g') {
            return c6 - 'W';
        }
        if ('A' > c6 || c6 >= 'G') {
            return -1;
        }
        return c6 - '7';
    }

    public static final int q(X4.o oVar) {
        AbstractC0983h.e("<this>", oVar);
        return (oVar.f() & 255) | ((oVar.f() & 255) << 16) | ((oVar.f() & 255) << 8);
    }

    public static final boolean r(u uVar, int i) {
        TimeUnit timeUnit = TimeUnit.MILLISECONDS;
        AbstractC0983h.e("timeUnit", timeUnit);
        long jNanoTime = System.nanoTime();
        long jC = uVar.d().e() ? uVar.d().c() - jNanoTime : Long.MAX_VALUE;
        uVar.d().d(Math.min(jC, timeUnit.toNanos(i)) + jNanoTime);
        try {
            e eVar = new e();
            while (uVar.p(eVar, 8192L) != -1) {
                eVar.r(eVar.f3321l);
            }
            if (jC == Long.MAX_VALUE) {
                uVar.d().a();
                return true;
            }
            uVar.d().d(jNanoTime + jC);
            return true;
        } catch (InterruptedIOException unused) {
            if (jC == Long.MAX_VALUE) {
                uVar.d().a();
                return false;
            }
            uVar.d().d(jNanoTime + jC);
            return false;
        } catch (Throwable th) {
            if (jC == Long.MAX_VALUE) {
                uVar.d().a();
            } else {
                uVar.d().d(jNanoTime + jC);
            }
            throw th;
        }
    }

    public static final m s(List list) {
        ArrayList arrayList = new ArrayList(20);
        Iterator it = list.iterator();
        while (it.hasNext()) {
            C0184c c0184c = (C0184c) it.next();
            String strH = c0184c.f2659a.h();
            String strH2 = c0184c.f2660b.h();
            arrayList.add(strH);
            arrayList.add(i.c0(strH2).toString());
        }
        Object[] array = arrayList.toArray(new String[0]);
        if (array != null) {
            return new m((String[]) array);
        }
        throw new NullPointerException("null cannot be cast to non-null type kotlin.Array<T of kotlin.collections.ArraysKt__ArraysJVMKt.toTypedArray>");
    }

    public static final String t(o oVar, boolean z5) {
        AbstractC0983h.e("<this>", oVar);
        String str = oVar.f1161d;
        if (i.I(str, ":", false)) {
            str = "[" + str + ']';
        }
        int i = oVar.f1162e;
        if (!z5) {
            String str2 = oVar.f1158a;
            AbstractC0983h.e("scheme", str2);
            if (i == (str2.equals("http") ? 80 : str2.equals("https") ? 443 : -1)) {
                return str;
            }
        }
        return str + ':' + i;
    }

    public static final List u(List list) {
        AbstractC0983h.e("<this>", list);
        List listUnmodifiableList = Collections.unmodifiableList(AbstractC0565i.o0(list));
        AbstractC0983h.d("unmodifiableList(toMutableList())", listUnmodifiableList);
        return listUnmodifiableList;
    }

    public static final int v(int i, String str) {
        Long lValueOf;
        if (str == null) {
            lValueOf = null;
        } else {
            try {
                lValueOf = Long.valueOf(Long.parseLong(str));
            } catch (NumberFormatException unused) {
                return i;
            }
        }
        if (lValueOf == null) {
            return i;
        }
        long jLongValue = lValueOf.longValue();
        if (jLongValue > 2147483647L) {
            return Integer.MAX_VALUE;
        }
        if (jLongValue < 0) {
            return 0;
        }
        return (int) jLongValue;
    }

    public static final String w(int i, String str, int i5) {
        int iL = l(i, str, i5);
        String strSubstring = str.substring(iL, m(iL, str, i5));
        AbstractC0983h.d("this as java.lang.String…ing(startIndex, endIndex)", strSubstring);
        return strSubstring;
    }

    public static final void x(IOException iOException, List list) {
        AbstractC0983h.e("<this>", iOException);
        if (list.size() > 1) {
            System.out.println(list);
        }
        Iterator it = list.iterator();
        while (it.hasNext()) {
            d.a(iOException, (Exception) it.next());
        }
    }
}
