package okhttp3.internal; import android.support.v4.media.session.PlaybackStateCompat; import com.facebook.internal.security.CertificateUtil; import com.ironsource.v8; import java.io.Closeable; import java.io.IOException; import java.io.InterruptedIOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.IDN; import java.net.InetAddress; import java.net.Socket; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.security.AccessControlException; import java.security.GeneralSecurityException; import java.security.KeyStore; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.TimeZone; import java.util.concurrent.ThreadFactory; import java.util.concurrent.TimeUnit; import java.util.regex.Pattern; import javax.net.ssl.TrustManager; import javax.net.ssl.TrustManagerFactory; import javax.net.ssl.X509TrustManager; import okhttp3.Headers; import okhttp3.HttpUrl; import okhttp3.MediaType; import okhttp3.RequestBody; import okhttp3.ResponseBody; import okhttp3.internal.http2.Header; import okio.Buffer; import okio.BufferedSource; import okio.ByteString; import okio.Options; import okio.Source; /* loaded from: classes5.dex */ public abstract class Util { public static final byte[] EMPTY_BYTE_ARRAY; public static final RequestBody EMPTY_REQUEST; public static final ResponseBody EMPTY_RESPONSE; public static final Pattern VERIFY_AS_IP_ADDRESS; public static final Method addSuppressedExceptionMethod; public static final String[] EMPTY_STRING_ARRAY = new String[0]; public static final Headers EMPTY_HEADERS = Headers.of(new String[0]); public static final Options UNICODE_BOMS = Options.of(ByteString.decodeHex("efbbbf"), ByteString.decodeHex("feff"), ByteString.decodeHex("fffe"), ByteString.decodeHex("0000ffff"), ByteString.decodeHex("ffff0000")); public static final Charset UTF_32BE = Charset.forName("UTF-32BE"); public static final Charset UTF_32LE = Charset.forName("UTF-32LE"); public static final TimeZone UTC = TimeZone.getTimeZone("GMT"); public static final Comparator NATURAL_ORDER = new Comparator() { // from class: okhttp3.internal.Util$$ExternalSyntheticLambda1 @Override // java.util.Comparator public final int compare(Object obj, Object obj2) { return ((String) obj).compareTo((String) obj2); } }; public static int decodeHexDigit(char c) { if (c >= '0' && c <= '9') { return c - '0'; } if (c >= 'a' && c <= 'f') { return c - 'W'; } if (c < 'A' || c > 'F') { return -1; } return c - '7'; } static { byte[] bArr = new byte[0]; EMPTY_BYTE_ARRAY = bArr; Method method = null; EMPTY_RESPONSE = ResponseBody.create((MediaType) null, bArr); EMPTY_REQUEST = RequestBody.create((MediaType) null, bArr); try { method = Throwable.class.getDeclaredMethod("addSuppressed", Throwable.class); } catch (Exception unused) { } addSuppressedExceptionMethod = method; VERIFY_AS_IP_ADDRESS = Pattern.compile("([0-9a-fA-F]*:[0-9a-fA-F:.]*)|([\\d.]+)"); } public static void addSuppressedIfPossible(Throwable th, Throwable th2) { Method method = addSuppressedExceptionMethod; if (method != null) { try { method.invoke(th, th2); } catch (IllegalAccessException | InvocationTargetException unused) { } } } public static void checkOffsetAndCount(long j, long j2, long j3) { if ((j2 | j3) < 0 || j2 > j || j - j2 < j3) { throw new ArrayIndexOutOfBoundsException(); } } public static void closeQuietly(Closeable closeable) { if (closeable != null) { try { closeable.close(); } catch (RuntimeException e) { throw e; } catch (Exception unused) { } } } public static void closeQuietly(Socket socket) { if (socket != null) { try { socket.close(); } catch (AssertionError e) { if (!isAndroidGetsocknameError(e)) { throw e; } } catch (RuntimeException e2) { throw e2; } catch (Exception unused) { } } } public static boolean discard(Source source, int i, TimeUnit timeUnit) { try { return skipAll(source, i, timeUnit); } catch (IOException unused) { return false; } } public static boolean skipAll(Source source, int i, TimeUnit timeUnit) { long nanoTime = System.nanoTime(); long deadlineNanoTime = source.timeout().hasDeadline() ? source.timeout().deadlineNanoTime() - nanoTime : Long.MAX_VALUE; source.timeout().deadlineNanoTime(Math.min(deadlineNanoTime, timeUnit.toNanos(i)) + nanoTime); try { Buffer buffer = new Buffer(); while (source.read(buffer, PlaybackStateCompat.ACTION_PLAY_FROM_URI) != -1) { buffer.clear(); } if (deadlineNanoTime == Long.MAX_VALUE) { source.timeout().clearDeadline(); return true; } source.timeout().deadlineNanoTime(nanoTime + deadlineNanoTime); return true; } catch (InterruptedIOException unused) { if (deadlineNanoTime == Long.MAX_VALUE) { source.timeout().clearDeadline(); return false; } source.timeout().deadlineNanoTime(nanoTime + deadlineNanoTime); return false; } catch (Throwable th) { if (deadlineNanoTime == Long.MAX_VALUE) { source.timeout().clearDeadline(); } else { source.timeout().deadlineNanoTime(nanoTime + deadlineNanoTime); } throw th; } } public static List immutableList(List list) { return Collections.unmodifiableList(new ArrayList(list)); } public static Map immutableMap(Map map) { if (map.isEmpty()) { return Collections.emptyMap(); } return Collections.unmodifiableMap(new LinkedHashMap(map)); } public static List immutableList(Object... objArr) { return Collections.unmodifiableList(Arrays.asList((Object[]) objArr.clone())); } public static ThreadFactory threadFactory(final String str, final boolean z) { return new ThreadFactory() { // from class: okhttp3.internal.Util$$ExternalSyntheticLambda0 @Override // java.util.concurrent.ThreadFactory public final Thread newThread(Runnable runnable) { Thread lambda$threadFactory$0; lambda$threadFactory$0 = Util.lambda$threadFactory$0(str, z, runnable); return lambda$threadFactory$0; } }; } public static /* synthetic */ Thread lambda$threadFactory$0(String str, boolean z, Runnable runnable) { Thread thread = new Thread(runnable, str); thread.setDaemon(z); return thread; } public static String[] intersect(Comparator comparator, String[] strArr, String[] strArr2) { 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[arrayList.size()]); } public static boolean nonEmptyIntersection(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; } public static String hostHeader(HttpUrl httpUrl, boolean z) { String host; if (httpUrl.host().contains(CertificateUtil.DELIMITER)) { host = v8.i.d + httpUrl.host() + v8.i.e; } else { host = httpUrl.host(); } if (!z && httpUrl.port() == HttpUrl.defaultPort(httpUrl.scheme())) { return host; } return host + CertificateUtil.DELIMITER + httpUrl.port(); } public static boolean isAndroidGetsocknameError(AssertionError assertionError) { return (assertionError.getCause() == null || assertionError.getMessage() == null || !assertionError.getMessage().contains("getsockname failed")) ? false : true; } public static int indexOf(Comparator comparator, String[] strArr, String str) { int length = strArr.length; for (int i = 0; i < length; i++) { if (comparator.compare(strArr[i], str) == 0) { return i; } } return -1; } public static String[] concat(String[] strArr, String str) { int length = strArr.length; String[] strArr2 = new String[length + 1]; System.arraycopy(strArr, 0, strArr2, 0, strArr.length); strArr2[length] = str; return strArr2; } public static int skipLeadingAsciiWhitespace(String str, int i, int i2) { while (i < i2) { char charAt = str.charAt(i); if (charAt != '\t' && charAt != '\n' && charAt != '\f' && charAt != '\r' && charAt != ' ') { return i; } i++; } return i2; } public static int skipTrailingAsciiWhitespace(String str, int i, int i2) { for (int i3 = i2 - 1; i3 >= i; i3--) { char charAt = str.charAt(i3); if (charAt != '\t' && charAt != '\n' && charAt != '\f' && charAt != '\r' && charAt != ' ') { return i3 + 1; } } return i; } public static String trimSubstring(String str, int i, int i2) { int skipLeadingAsciiWhitespace = skipLeadingAsciiWhitespace(str, i, i2); return str.substring(skipLeadingAsciiWhitespace, skipTrailingAsciiWhitespace(str, skipLeadingAsciiWhitespace, i2)); } public static int delimiterOffset(String str, int i, int i2, String str2) { while (i < i2) { if (str2.indexOf(str.charAt(i)) != -1) { return i; } i++; } return i2; } public static int delimiterOffset(String str, int i, int i2, char c) { while (i < i2) { if (str.charAt(i) == c) { return i; } i++; } return i2; } public static String canonicalizeHost(String str) { InetAddress decodeIpv6; if (str.contains(CertificateUtil.DELIMITER)) { if (str.startsWith(v8.i.d) && str.endsWith(v8.i.e)) { decodeIpv6 = decodeIpv6(str, 1, str.length() - 1); } else { decodeIpv6 = decodeIpv6(str, 0, str.length()); } if (decodeIpv6 == null) { return null; } byte[] address = decodeIpv6.getAddress(); if (address.length == 16) { return inet6AddressToAscii(address); } if (address.length == 4) { return decodeIpv6.getHostAddress(); } throw new AssertionError("Invalid IPv6 address: '" + str + "'"); } try { String lowerCase = IDN.toASCII(str).toLowerCase(Locale.US); if (lowerCase.isEmpty()) { return null; } if (containsInvalidHostnameAsciiCodes(lowerCase)) { return null; } return lowerCase; } catch (IllegalArgumentException unused) { return null; } } public static boolean containsInvalidHostnameAsciiCodes(String str) { for (int i = 0; i < str.length(); i++) { char charAt = str.charAt(i); if (charAt <= 31 || charAt >= 127 || " #%/:?@[\\]".indexOf(charAt) != -1) { return true; } } return false; } public static int indexOfControlOrNonAscii(String str) { int length = str.length(); for (int i = 0; i < length; i++) { char charAt = str.charAt(i); if (charAt <= 31 || charAt >= 127) { return i; } } return -1; } public static boolean verifyAsIpAddress(String str) { return VERIFY_AS_IP_ADDRESS.matcher(str).matches(); } public static String format(String str, Object... objArr) { return String.format(Locale.US, str, objArr); } public static Charset bomAwareCharset(BufferedSource bufferedSource, Charset charset) { int select = bufferedSource.select(UNICODE_BOMS); if (select == -1) { return charset; } if (select == 0) { return StandardCharsets.UTF_8; } if (select == 1) { return StandardCharsets.UTF_16BE; } if (select == 2) { return StandardCharsets.UTF_16LE; } if (select == 3) { return UTF_32BE; } if (select == 4) { return UTF_32LE; } throw new AssertionError(); } public static int checkDuration(String str, long j, TimeUnit timeUnit) { if (j < 0) { throw new IllegalArgumentException(str + " < 0"); } if (timeUnit == null) { throw new NullPointerException("unit == null"); } long millis = timeUnit.toMillis(j); if (millis > 2147483647L) { throw new IllegalArgumentException(str + " too large."); } if (millis != 0 || j <= 0) { return (int) millis; } throw new IllegalArgumentException(str + " too small."); } /* JADX WARN: Code restructure failed: missing block: B:25:0x0078, 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 add '--show-bad-code' argument */ public static java.net.InetAddress decodeIpv6(java.lang.String r12, int r13, int r14) { /* r0 = 16 byte[] r1 = new byte[r0] r2 = 0 r3 = -1 r4 = r2 r5 = r3 r6 = r5 L9: r7 = 0 if (r13 >= r14) goto L79 if (r4 != r0) goto Lf return r7 Lf: int r8 = r13 + 2 r9 = 2 if (r8 > r14) goto L27 java.lang.String r10 = "::" boolean r10 = r12.regionMatches(r13, r10, r2, r9) if (r10 == 0) goto L27 if (r5 == r3) goto L1f return r7 L1f: int r4 = r4 + 2 r5 = r4 if (r8 != r14) goto L25 goto L79 L25: r6 = r8 goto L4b L27: if (r4 == 0) goto L34 java.lang.String r8 = ":" r10 = 1 boolean r8 = r12.regionMatches(r13, r8, r2, r10) if (r8 == 0) goto L36 int r13 = r13 + 1 L34: r6 = r13 goto L4b L36: java.lang.String r8 = "." boolean r13 = r12.regionMatches(r13, r8, r2, r10) if (r13 == 0) goto L4a int r13 = r4 + (-2) boolean r12 = decodeIpv4Suffix(r12, r6, r14, r1, r13) if (r12 != 0) goto L47 return r7 L47: int r4 = r4 + 2 goto L79 L4a: return r7 L4b: r8 = r2 r13 = r6 L4d: if (r13 >= r14) goto L60 char r10 = r12.charAt(r13) int r10 = decodeHexDigit(r10) if (r10 != r3) goto L5a goto L60 L5a: int r8 = r8 << 4 int r8 = r8 + r10 int r13 = r13 + 1 goto L4d L60: int r10 = r13 - r6 if (r10 == 0) goto L78 r11 = 4 if (r10 <= r11) goto L68 goto L78 L68: int r7 = r4 + 1 int r10 = r8 >>> 8 r10 = r10 & 255(0xff, float:3.57E-43) byte r10 = (byte) r10 r1[r4] = r10 int r4 = r4 + r9 r8 = r8 & 255(0xff, float:3.57E-43) byte r8 = (byte) r8 r1[r7] = r8 goto L9 L78: return r7 L79: if (r4 == r0) goto L8a if (r5 != r3) goto L7e return r7 L7e: int r12 = r4 - r5 int r13 = 16 - r12 java.lang.System.arraycopy(r1, r5, r1, r13, r12) int r0 = r0 - r4 int r0 = r0 + r5 java.util.Arrays.fill(r1, r5, r0, r2) L8a: java.net.InetAddress r12 = java.net.InetAddress.getByAddress(r1) // Catch: java.net.UnknownHostException -> L8f return r12 L8f: java.lang.AssertionError r12 = new java.lang.AssertionError r12.() throw r12 */ throw new UnsupportedOperationException("Method not decompiled: okhttp3.internal.Util.decodeIpv6(java.lang.String, int, int):java.net.InetAddress"); } public static boolean decodeIpv4Suffix(String str, int i, int i2, byte[] bArr, int i3) { int i4 = i3; while (i < i2) { if (i4 == bArr.length) { return false; } if (i4 != i3) { if (str.charAt(i) != '.') { return false; } i++; } int i5 = i; int i6 = 0; while (i5 < i2) { char charAt = str.charAt(i5); if (charAt < '0' || charAt > '9') { break; } if ((i6 == 0 && i != i5) || (i6 = ((i6 * 10) + charAt) - 48) > 255) { return false; } i5++; } if (i5 - i == 0) { return false; } bArr[i4] = (byte) i6; i4++; i = i5; } return i4 == i3 + 4; } public static String inet6AddressToAscii(byte[] bArr) { int i = -1; int i2 = 0; int i3 = 0; int i4 = 0; while (i3 < bArr.length) { int i5 = i3; while (i5 < 16 && bArr[i5] == 0 && bArr[i5 + 1] == 0) { i5 += 2; } int i6 = i5 - i3; if (i6 > i4 && i6 >= 4) { i = i3; i4 = i6; } i3 = i5 + 2; } Buffer buffer = new Buffer(); while (i2 < bArr.length) { if (i2 == i) { buffer.writeByte(58); i2 += i4; if (i2 == 16) { buffer.writeByte(58); } } else { if (i2 > 0) { buffer.writeByte(58); } buffer.writeHexadecimalUnsignedLong(((bArr[i2] & 255) << 8) | (bArr[i2 + 1] & 255)); i2 += 2; } } return buffer.readUtf8(); } public static X509TrustManager platformTrustManager() { try { TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); trustManagerFactory.init((KeyStore) null); TrustManager[] trustManagers = trustManagerFactory.getTrustManagers(); if (trustManagers.length == 1) { TrustManager trustManager = trustManagers[0]; if (trustManager instanceof X509TrustManager) { return (X509TrustManager) trustManager; } } throw new IllegalStateException("Unexpected default trust managers:" + Arrays.toString(trustManagers)); } catch (GeneralSecurityException e) { throw new AssertionError("No System TLS", e); } } public static Headers toHeaders(List list) { Headers.Builder builder = new Headers.Builder(); Iterator it = list.iterator(); while (it.hasNext()) { Header header = (Header) it.next(); Internal.instance.addLenient(builder, header.name.utf8(), header.value.utf8()); } return builder.build(); } public static List toHeaderBlock(Headers headers) { ArrayList arrayList = new ArrayList(); for (int i = 0; i < headers.size(); i++) { arrayList.add(new Header(headers.name(i), headers.value(i))); } return arrayList; } public static String getSystemProperty(String str, String str2) { try { String property = System.getProperty(str); return property != null ? property : str2; } catch (AccessControlException unused) { return str2; } } public static boolean sameConnection(HttpUrl httpUrl, HttpUrl httpUrl2) { return httpUrl.host().equals(httpUrl2.host()) && httpUrl.port() == httpUrl2.port() && httpUrl.scheme().equals(httpUrl2.scheme()); } }