package i5; import h5.b0; import h5.f; import h5.g; import h5.k0; import h5.l0; import h5.o0; import h5.p0; import java.io.Closeable; import java.io.IOException; import java.io.InterruptedIOException; import java.net.IDN; import java.net.InetAddress; 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.List; import java.util.Locale; import java.util.TimeZone; import java.util.concurrent.ThreadFactory; import java.util.concurrent.TimeUnit; import java.util.regex.Pattern; /* loaded from: classes2.dex */ public abstract class c { /* renamed from: a, reason: collision with root package name */ public static final byte[] f10871a; /* renamed from: c, reason: collision with root package name */ public static final l0 f10873c; /* renamed from: d, reason: collision with root package name */ public static final k0 f10874d; /* renamed from: b, reason: collision with root package name */ public static final String[] f10872b = new String[0]; /* renamed from: e, reason: collision with root package name */ private static final g f10875e = g.g("efbbbf"); /* renamed from: f, reason: collision with root package name */ private static final g f10876f = g.g("feff"); /* renamed from: g, reason: collision with root package name */ private static final g f10877g = g.g("fffe"); /* renamed from: h, reason: collision with root package name */ private static final g f10878h = g.g("0000ffff"); /* renamed from: i, reason: collision with root package name */ private static final g f10879i = g.g("ffff0000"); /* renamed from: j, reason: collision with root package name */ public static final Charset f10880j = StandardCharsets.UTF_8; /* renamed from: k, reason: collision with root package name */ public static final Charset f10881k = StandardCharsets.ISO_8859_1; /* renamed from: l, reason: collision with root package name */ private static final Charset f10882l = StandardCharsets.UTF_16BE; /* renamed from: m, reason: collision with root package name */ private static final Charset f10883m = StandardCharsets.UTF_16LE; /* renamed from: n, reason: collision with root package name */ private static final Charset f10884n = Charset.forName("UTF-32BE"); /* renamed from: o, reason: collision with root package name */ private static final Charset f10885o = Charset.forName("UTF-32LE"); /* renamed from: p, reason: collision with root package name */ public static final TimeZone f10886p = TimeZone.getTimeZone("GMT"); /* renamed from: q, reason: collision with root package name */ public static final Comparator f10887q = new a(); /* renamed from: r, reason: collision with root package name */ private static final Pattern f10888r = Pattern.compile("([0-9a-fA-F]*:[0-9a-fA-F:.]*)|([\\d.]+)"); class a implements Comparator { a() { } @Override // java.util.Comparator /* renamed from: a, reason: merged with bridge method [inline-methods] */ public int compare(String str, String str2) { return str.compareTo(str2); } } class b implements ThreadFactory { /* renamed from: a, reason: collision with root package name */ final /* synthetic */ String f10889a; /* renamed from: b, reason: collision with root package name */ final /* synthetic */ boolean f10890b; b(String str, boolean z10) { this.f10889a = str; this.f10890b = z10; } @Override // java.util.concurrent.ThreadFactory public Thread newThread(Runnable runnable) { Thread thread = new Thread(runnable, this.f10889a); thread.setDaemon(this.f10890b); return thread; } } static { byte[] bArr = new byte[0]; f10871a = bArr; f10873c = l0.O(null, bArr); f10874d = k0.c(null, bArr); } public static boolean A(o0 o0Var, int i10, TimeUnit timeUnit) { long nanoTime = System.nanoTime(); long c10 = o0Var.b().e() ? o0Var.b().c() - nanoTime : Long.MAX_VALUE; o0Var.b().d(Math.min(c10, timeUnit.toNanos(i10)) + nanoTime); try { h5.d dVar = new h5.d(); while (o0Var.H(dVar, 8192L) != -1) { dVar.P(); } p0 b10 = o0Var.b(); if (c10 == Long.MAX_VALUE) { b10.a(); return true; } b10.d(nanoTime + c10); return true; } catch (InterruptedIOException unused) { p0 b11 = o0Var.b(); if (c10 == Long.MAX_VALUE) { b11.a(); return false; } b11.d(nanoTime + c10); return false; } catch (Throwable th) { p0 b12 = o0Var.b(); if (c10 == Long.MAX_VALUE) { b12.a(); } else { b12.d(nanoTime + c10); } throw th; } } public static int B(String str, int i10, int i11) { while (i10 < i11) { char charAt = str.charAt(i10); if (charAt != '\t' && charAt != '\n' && charAt != '\f' && charAt != '\r' && charAt != ' ') { return i10; } i10++; } return i11; } public static int C(String str, int i10, int i11) { for (int i12 = i11 - 1; i12 >= i10; i12--) { char charAt = str.charAt(i12); if (charAt != '\t' && charAt != '\n' && charAt != '\f' && charAt != '\r' && charAt != ' ') { return i12 + 1; } } return i10; } public static ThreadFactory D(String str, boolean z10) { return new b(str, z10); } public static String E(String str, int i10, int i11) { int B = B(str, i10, i11); return str.substring(B, C(str, B, i11)); } public static boolean F(String str) { return f10888r.matcher(str).matches(); } private static String a(byte[] bArr) { int i10 = -1; int i11 = 0; int i12 = 0; int i13 = 0; while (i12 < bArr.length) { int i14 = i12; while (i14 < 16 && bArr[i14] == 0 && bArr[i14 + 1] == 0) { i14 += 2; } int i15 = i14 - i12; if (i15 > i13 && i15 >= 4) { i10 = i12; i13 = i15; } i12 = i14 + 2; } h5.d dVar = new h5.d(); while (i11 < bArr.length) { if (i11 == i10) { dVar.h(58); i11 += i13; if (i11 == 16) { dVar.h(58); } } else { if (i11 > 0) { dVar.h(58); } dVar.m(((bArr[i11] & 255) << 8) | (bArr[i11 + 1] & 255)); i11 += 2; } } return dVar.q0(); } /* JADX WARN: Code restructure failed: missing block: B:25:0x0079, code lost: return null; */ /* JADX WARN: Removed duplicated region for block: B:15:0x004f */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct code enable 'Show inconsistent code' option in preferences */ private static java.net.InetAddress b(java.lang.String r11, int r12, int r13) { /* r0 = 16 byte[] r1 = new byte[r0] r2 = 0 r3 = -1 r4 = 0 r5 = -1 r6 = -1 L9: r7 = 0 if (r12 >= r13) goto L7a if (r4 != r0) goto Lf return r7 Lf: int r8 = r12 + 2 if (r8 > r13) goto L27 java.lang.String r9 = "::" r10 = 2 boolean r9 = r11.regionMatches(r12, r9, r2, r10) if (r9 == 0) goto L27 if (r5 == r3) goto L1f return r7 L1f: int r4 = r4 + 2 r5 = r4 if (r8 != r13) goto L25 goto L7a L25: r6 = r8 goto L4b L27: if (r4 == 0) goto L4a java.lang.String r8 = ":" r9 = 1 boolean r8 = r11.regionMatches(r12, r8, r2, r9) if (r8 == 0) goto L35 int r12 = r12 + 1 goto L4a L35: java.lang.String r8 = "." boolean r12 = r11.regionMatches(r12, r8, r2, r9) if (r12 == 0) goto L49 int r12 = r4 + (-2) boolean r11 = d(r11, r6, r13, r1, r12) if (r11 != 0) goto L46 return r7 L46: int r4 = r4 + 2 goto L7a L49: return r7 L4a: r6 = r12 L4b: r12 = r6 r8 = 0 L4d: if (r12 >= r13) goto L60 char r9 = r11.charAt(r12) int r9 = m(r9) if (r9 != r3) goto L5a goto L60 L5a: int r8 = r8 << 4 int r8 = r8 + r9 int r12 = r12 + 1 goto L4d L60: int r9 = r12 - r6 if (r9 == 0) goto L79 r10 = 4 if (r9 <= r10) goto L68 goto L79 L68: int r7 = r4 + 1 int r9 = r8 >>> 8 r9 = r9 & 255(0xff, float:3.57E-43) byte r9 = (byte) r9 r1[r4] = r9 int r4 = r7 + 1 r8 = r8 & 255(0xff, float:3.57E-43) byte r8 = (byte) r8 r1[r7] = r8 goto L9 L79: return r7 L7a: if (r4 == r0) goto L8b if (r5 != r3) goto L7f return r7 L7f: int r11 = r4 - r5 int r12 = 16 - r11 java.lang.System.arraycopy(r1, r5, r1, r12, r11) int r0 = r0 - r4 int r0 = r0 + r5 java.util.Arrays.fill(r1, r5, r0, r2) L8b: java.net.InetAddress r11 = java.net.InetAddress.getByAddress(r1) // Catch: java.net.UnknownHostException -> L90 return r11 L90: java.lang.AssertionError r11 = new java.lang.AssertionError r11.() throw r11 */ throw new UnsupportedOperationException("Method not decompiled: i5.c.b(java.lang.String, int, int):java.net.InetAddress"); } private static boolean c(String str) { for (int i10 = 0; i10 < str.length(); i10++) { char charAt = str.charAt(i10); if (charAt <= 31 || charAt >= 127 || " #%/:?@[\\]".indexOf(charAt) != -1) { return true; } } return false; } private static boolean d(String str, int i10, int i11, byte[] bArr, int i12) { int i13 = i12; while (i10 < i11) { if (i13 == bArr.length) { return false; } if (i13 != i12) { if (str.charAt(i10) != '.') { return false; } i10++; } int i14 = i10; int i15 = 0; while (i14 < i11) { char charAt = str.charAt(i14); if (charAt < '0' || charAt > '9') { break; } if ((i15 == 0 && i10 != i14) || (i15 = ((i15 * 10) + charAt) - 48) > 255) { return false; } i14++; } if (i14 - i10 == 0) { return false; } bArr[i13] = (byte) i15; i13++; i10 = i14; } return i13 == i12 + 4; } public static AssertionError e(String str, Exception exc) { AssertionError assertionError = new AssertionError(str); try { assertionError.initCause(exc); } catch (IllegalStateException unused) { } return assertionError; } public static Charset f(f fVar, Charset charset) { if (fVar.g0(0L, f10875e)) { fVar.skip(r0.o()); return f10880j; } if (fVar.g0(0L, f10876f)) { fVar.skip(r0.o()); return f10882l; } if (fVar.g0(0L, f10877g)) { fVar.skip(r0.o()); return f10883m; } if (fVar.g0(0L, f10878h)) { fVar.skip(r0.o()); return f10884n; } if (!fVar.g0(0L, f10879i)) { return charset; } fVar.skip(r0.o()); return f10885o; } public static String g(String str) { int length; int i10; if (!str.contains(":")) { try { String lowerCase = IDN.toASCII(str).toLowerCase(Locale.US); if (lowerCase.isEmpty()) { return null; } if (c(lowerCase)) { return null; } return lowerCase; } catch (IllegalArgumentException unused) { return null; } } if (str.startsWith("[") && str.endsWith("]")) { i10 = 1; length = str.length() - 1; } else { length = str.length(); i10 = 0; } InetAddress b10 = b(str, i10, length); if (b10 == null) { return null; } byte[] address = b10.getAddress(); if (address.length == 16) { return a(address); } throw new AssertionError("Invalid IPv6 address: '" + str + "'"); } public static int h(String str, long j10, TimeUnit timeUnit) { if (j10 < 0) { throw new IllegalArgumentException(str + " < 0"); } if (timeUnit == null) { throw new NullPointerException("unit == null"); } long millis = timeUnit.toMillis(j10); if (millis > 2147483647L) { throw new IllegalArgumentException(str + " too large."); } if (millis != 0 || j10 <= 0) { return (int) millis; } throw new IllegalArgumentException(str + " too small."); } public static void i(long j10, long j11, long j12) { if ((j11 | j12) < 0 || j11 > j10 || j10 - j11 < j12) { throw new ArrayIndexOutOfBoundsException(); } } public static void j(Closeable closeable) { if (closeable != null) { try { closeable.close(); } catch (RuntimeException e10) { throw e10; } catch (Exception unused) { } } } public static void k(Socket socket) { if (socket != null) { try { socket.close(); } catch (AssertionError e10) { if (!y(e10)) { throw e10; } } catch (RuntimeException e11) { throw e11; } catch (Exception unused) { } } } public static String[] l(String[] strArr, String str) { int length = strArr.length + 1; String[] strArr2 = new String[length]; System.arraycopy(strArr, 0, strArr2, 0, strArr.length); strArr2[length - 1] = str; return strArr2; } public static int m(char c10) { if (c10 >= '0' && c10 <= '9') { return c10 - '0'; } char c11 = 'a'; if (c10 < 'a' || c10 > 'f') { c11 = 'A'; if (c10 < 'A' || c10 > 'F') { return -1; } } return (c10 - c11) + 10; } public static int n(String str, int i10, int i11, char c10) { while (i10 < i11) { if (str.charAt(i10) == c10) { return i10; } i10++; } return i11; } public static int o(String str, int i10, int i11, String str2) { while (i10 < i11) { if (str2.indexOf(str.charAt(i10)) != -1) { return i10; } i10++; } return i11; } public static boolean p(o0 o0Var, int i10, TimeUnit timeUnit) { try { return A(o0Var, i10, timeUnit); } catch (IOException unused) { return false; } } public static boolean q(Object obj, Object obj2) { return obj == obj2 || (obj != null && obj.equals(obj2)); } public static String r(String str, Object... objArr) { return String.format(Locale.US, str, objArr); } public static String s(b0 b0Var, boolean z10) { String t10; if (b0Var.t().contains(":")) { t10 = "[" + b0Var.t() + "]"; } else { t10 = b0Var.t(); } if (!z10 && b0Var.y() == b0.m(b0Var.C())) { return t10; } return t10 + ":" + b0Var.y(); } public static List t(List list) { return Collections.unmodifiableList(new ArrayList(list)); } public static List u(Object... objArr) { return Collections.unmodifiableList(Arrays.asList((Object[]) objArr.clone())); } public static int v(Comparator comparator, String[] strArr, String str) { int length = strArr.length; for (int i10 = 0; i10 < length; i10++) { if (comparator.compare(strArr[i10], str) == 0) { return i10; } } return -1; } public static int w(String str) { int length = str.length(); for (int i10 = 0; i10 < length; i10++) { char charAt = str.charAt(i10); if (charAt <= 31 || charAt >= 127) { return i10; } } return -1; } public static String[] x(Comparator comparator, String[] strArr, String[] strArr2) { ArrayList arrayList = new ArrayList(); for (String str : strArr) { int length = strArr2.length; int i10 = 0; while (true) { if (i10 >= length) { break; } if (comparator.compare(str, strArr2[i10]) == 0) { arrayList.add(str); break; } i10++; } } return (String[]) arrayList.toArray(new String[arrayList.size()]); } public static boolean y(AssertionError assertionError) { return (assertionError.getCause() == null || assertionError.toString() == null || !assertionError.toString().contains("getsockname failed")) ? false : true; } public static boolean z(Comparator comparator, String[] strArr, String[] strArr2) { if (strArr != null && strArr2 != null && strArr.length != 0 && strArr2.length != 0) { for (String str : strArr) { for (String str2 : strArr2) { if (comparator.compare(str, str2) == 0) { return true; } } } } return false; } }