package o;

import com.google.android.gms.common.api.Api;
import java.io.Closeable;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.Socket;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
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.TimeZone;
import java.util.concurrent.TimeUnit;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.qi0, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public abstract class AbstractC2264qi0 {
    public static final byte[] a;
    public static final LE b = AbstractC2001nt0.z(new String[0]);
    public static final D20 c;
    public static final MU d;
    public static final TimeZone e;
    public static final G10 f;
    public static final String g;

    /* JADX WARN: Code restructure failed: missing block: B:46:0x010d, code lost:
    
        continue;
     */
    static {
        /*
            Method dump skipped, instructions count: 383
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: o.AbstractC2264qi0.<clinit>():void");
    }

    public static final boolean a(ZF zf, ZF zf2) {
        return F3.c(zf.d, zf2.d) && zf.e == zf2.e && F3.c(zf.a, zf2.a);
    }

    public static final int b(long j, TimeUnit timeUnit) {
        if (j < 0) {
            throw new IllegalStateException("timeout".concat(" < 0").toString());
        }
        if (timeUnit == null) {
            throw new IllegalStateException("unit == null");
        }
        long millis = timeUnit.toMillis(j);
        if (millis > 2147483647L) {
            throw new IllegalArgumentException("timeout".concat(" too large.").toString());
        }
        if (millis != 0 || j <= 0) {
            return (int) millis;
        }
        throw new IllegalArgumentException("timeout".concat(" too small.").toString());
    }

    public static final void c(long j, long j2, long j3) {
        if ((j2 | j3) < 0 || j2 > j || j - j2 < j3) {
            throw new ArrayIndexOutOfBoundsException();
        }
    }

    public static final void d(Closeable closeable) throws IOException {
        try {
            closeable.close();
        } catch (RuntimeException e2) {
            throw e2;
        } catch (Exception unused) {
        }
    }

    public static final void e(Socket socket) throws IOException {
        try {
            socket.close();
        } catch (AssertionError e2) {
            throw e2;
        } catch (RuntimeException e3) {
            if (!F3.c(e3.getMessage(), "bio == null")) {
                throw e3;
            }
        } catch (Exception unused) {
        }
    }

    public static final int f(int i, int i2, String str, String str2) {
        while (i < i2) {
            if (Za0.Q(str2, str.charAt(i))) {
                return i;
            }
            i++;
        }
        return i2;
    }

    public static final int g(String str, char c2, int i, int i2) {
        while (i < i2) {
            if (str.charAt(i) == c2) {
                return i;
            }
            i++;
        }
        return i2;
    }

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

    /* JADX WARN: Code restructure failed: missing block: B:26:0x0033, code lost:
    
        r2 = r2 + 1;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public static final boolean i(java.lang.String[] r7, java.lang.String[] r8, java.util.Comparator r9) {
        /*
            int r0 = r7.length
            r1 = 0
            if (r0 != 0) goto L5
            goto L36
        L5:
            if (r8 == 0) goto L36
            int r0 = r8.length
            if (r0 != 0) goto Lb
            goto L36
        Lb:
            int r0 = r7.length
            r2 = r1
        Ld:
            if (r2 >= r0) goto L36
            r3 = r7[r2]
            r4 = r1
        L12:
            int r5 = r8.length
            r6 = 1
            if (r4 >= r5) goto L18
            r5 = r6
            goto L19
        L18:
            r5 = r1
        L19:
            if (r5 == 0) goto L33
            int r5 = r4 + 1
            r4 = r8[r4]     // Catch: java.lang.ArrayIndexOutOfBoundsException -> L28
            int r4 = r9.compare(r3, r4)
            if (r4 != 0) goto L26
            return r6
        L26:
            r4 = r5
            goto L12
        L28:
            r7 = move-exception
            java.util.NoSuchElementException r8 = new java.util.NoSuchElementException
            java.lang.String r7 = r7.getMessage()
            r8.<init>(r7)
            throw r8
        L33:
            int r2 = r2 + 1
            goto Ld
        L36:
            return r1
        */
        throw new UnsupportedOperationException("Method not decompiled: o.AbstractC2264qi0.i(java.lang.String[], java.lang.String[], java.util.Comparator):boolean");
    }

    public static final long j(C20 c20) {
        String strA = c20.q.a("Content-Length");
        if (strA == null) {
            return -1L;
        }
        try {
            return Long.parseLong(strA);
        } catch (NumberFormatException unused) {
            return -1L;
        }
    }

    public static final List k(Object... objArr) {
        Object[] objArr2 = (Object[]) objArr.clone();
        return Collections.unmodifiableList(AbstractC0008Ai.S(Arrays.copyOf(objArr2, objArr2.length)));
    }

    public static final int l(String str) {
        int length = str.length();
        for (int i = 0; i < length; i++) {
            char cCharAt = str.charAt(i);
            if (F3.m(cCharAt, 31) <= 0 || F3.m(cCharAt, 127) >= 0) {
                return i;
            }
        }
        return -1;
    }

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

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

    public static final String[] o(String[] strArr, String[] strArr2, Comparator comparator) {
        ArrayList arrayList = new ArrayList();
        for (String str : strArr) {
            int length = strArr2.length;
            int i = 0;
            while (true) {
                if (i >= length) {
                    break;
                }
                if (comparator.compare(str, strArr2[i]) == 0) {
                    arrayList.add(str);
                    break;
                }
                i++;
            }
        }
        return (String[]) arrayList.toArray(new String[0]);
    }

    public static final boolean p(String str) {
        return str.equalsIgnoreCase("Authorization") || str.equalsIgnoreCase("Cookie") || str.equalsIgnoreCase("Proxy-Authorization") || str.equalsIgnoreCase("Set-Cookie");
    }

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

    public static final Charset r(InterfaceC1687kf interfaceC1687kf, Charset charset) {
        int iP = interfaceC1687kf.P(d);
        if (iP == -1) {
            return charset;
        }
        if (iP == 0) {
            return StandardCharsets.UTF_8;
        }
        if (iP == 1) {
            return StandardCharsets.UTF_16BE;
        }
        if (iP == 2) {
            return StandardCharsets.UTF_16LE;
        }
        if (iP == 3) {
            Charset charset2 = AbstractC2355rh.a;
            Charset charset3 = AbstractC2355rh.c;
            if (charset3 != null) {
                return charset3;
            }
            Charset charsetForName = Charset.forName("UTF-32BE");
            AbstractC2355rh.c = charsetForName;
            return charsetForName;
        }
        if (iP != 4) {
            throw new AssertionError();
        }
        Charset charset4 = AbstractC2355rh.a;
        Charset charset5 = AbstractC2355rh.b;
        if (charset5 != null) {
            return charset5;
        }
        Charset charsetForName2 = Charset.forName("UTF-32LE");
        AbstractC2355rh.b = charsetForName2;
        return charsetForName2;
    }

    public static final int s(InterfaceC1687kf interfaceC1687kf) {
        return (interfaceC1687kf.readByte() & 255) | ((interfaceC1687kf.readByte() & 255) << 16) | ((interfaceC1687kf.readByte() & 255) << 8);
    }

    public static final boolean t(T90 t90, int i) {
        TimeUnit timeUnit = TimeUnit.MILLISECONDS;
        long jNanoTime = System.nanoTime();
        long jC = t90.a().e() ? t90.a().c() - jNanoTime : Long.MAX_VALUE;
        t90.a().d(Math.min(jC, timeUnit.toNanos(i)) + jNanoTime);
        try {
            C0732af c0732af = new C0732af();
            while (t90.C(8192L, c0732af) != -1) {
                c0732af.b();
            }
            if (jC == Long.MAX_VALUE) {
                t90.a().a();
                return true;
            }
            t90.a().d(jNanoTime + jC);
            return true;
        } catch (InterruptedIOException unused) {
            if (jC == Long.MAX_VALUE) {
                t90.a().a();
                return false;
            }
            t90.a().d(jNanoTime + jC);
            return false;
        } catch (Throwable th) {
            if (jC == Long.MAX_VALUE) {
                t90.a().a();
            } else {
                t90.a().d(jNanoTime + jC);
            }
            throw th;
        }
    }

    public static final LE u(List list) {
        ArrayList arrayList = new ArrayList(20);
        Iterator it = list.iterator();
        while (it.hasNext()) {
            JE je = (JE) it.next();
            C0135Ff c0135Ff = je.a;
            C0135Ff c0135Ff2 = je.b;
            String strN = c0135Ff.n();
            String strN2 = c0135Ff2.n();
            arrayList.add(strN);
            arrayList.add(Za0.o0(strN2).toString());
        }
        return new LE((String[]) arrayList.toArray(new String[0]));
    }

    public static final String v(ZF zf, boolean z) {
        int i = zf.e;
        String str = zf.d;
        if (Za0.P(str, ":", false)) {
            str = "[" + str + ']';
        }
        if (!z) {
            String str2 = zf.a;
            if (i == (str2.equals("http") ? 80 : str2.equals("https") ? 443 : -1)) {
                return str;
            }
        }
        return str + ':' + i;
    }

    public static final List w(List list) {
        return Collections.unmodifiableList(new ArrayList(list));
    }

    public static final int x(int i, String str) {
        if (str == null) {
            return i;
        }
        try {
            long j = Long.parseLong(str);
            if (j > 2147483647L) {
                return Api.BaseClientBuilder.API_PRIORITY_OTHER;
            }
            if (j < 0) {
                return 0;
            }
            return (int) j;
        } catch (NumberFormatException unused) {
            return i;
        }
    }
}
