package 㿎.ሽ;

import android.support.v4.media.session.PlaybackStateCompat;
import androidx.recyclerview.widget.RecyclerView;
import com.facebook.appevents.codeless.CodelessMatcher;
import com.facebook.internal.security.CertificateUtil;
import com.google.android.material.progressindicator.BaseProgressIndicator;
import com.google.zxing.qrcode.encoder.Encoder;
import java.io.Closeable;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.lang.reflect.Method;
import java.net.IDN;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
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 okio.ByteString;
import ඓ.K.K.K.C1293;
import ᨨ.AbstractC1494;
import ᨨ.AbstractC1496;
import ᨨ.C1492;
import 㿎.AbstractC2632;
import 㿎.AbstractC2651;
import 㿎.C2531;
import 㿎.C2628;

/* renamed from: 㿎.ሽ.ʬ  reason: contains not printable characters */
/* compiled from: Util */
public final class C2540 {

    /* renamed from: ʬ  reason: contains not printable characters */
    public static final AbstractC2632 f8560 = AbstractC2632.create((C2628) null, f8569);

    /* renamed from: Ԕ  reason: contains not printable characters */
    public static final TimeZone f8561 = TimeZone.getTimeZone("GMT");

    /* renamed from: ؿ  reason: contains not printable characters */
    public static final Method f8562;

    /* renamed from: ඓ  reason: contains not printable characters */
    public static final ByteString f8563 = ByteString.decodeHex("feff");

    /* renamed from: ᓣ  reason: contains not printable characters */
    public static final Pattern f8564 = Pattern.compile("([0-9a-fA-F]*:[0-9a-fA-F:.]*)|([\\d.]+)");

    /* renamed from: ᕣ  reason: contains not printable characters */
    public static final Charset f8565 = Charset.forName("UTF-16LE");

    /* renamed from: ᨨ  reason: contains not printable characters */
    public static final Charset f8566 = Charset.forName("UTF-8");

    /* renamed from: ῲ  reason: contains not printable characters */
    public static final String[] f8567 = new String[0];

    /* renamed from: ⁱ  reason: contains not printable characters */
    public static final ByteString f8568 = ByteString.decodeHex("0000ffff");

    /* renamed from: K  reason: contains not printable characters */
    public static final byte[] f8569 = new byte[0];

    /* renamed from: 㑃  reason: contains not printable characters */
    public static final Charset f8570 = Charset.forName("UTF-32BE");

    /* renamed from: 㗗  reason: contains not printable characters */
    public static final Comparator<String> f8571 = new C2542();

    /* renamed from: 㳳  reason: contains not printable characters */
    public static final Charset f8572 = Charset.forName("UTF-16BE");

    /* renamed from: 㴹  reason: contains not printable characters */
    public static final ByteString f8573 = ByteString.decodeHex("fffe");

    /* renamed from: 㸾  reason: contains not printable characters */
    public static final ByteString f8574 = ByteString.decodeHex("efbbbf");

    /* renamed from: 㿎  reason: contains not printable characters */
    public static final ByteString f8575 = ByteString.decodeHex("ffff0000");

    /* renamed from: 䁗  reason: contains not printable characters */
    public static final Charset f8576 = Charset.forName("UTF-32LE");

    /* renamed from: 㿎.ሽ.ʬ$ῲ  reason: contains not printable characters */
    /* compiled from: Util */
    public class ThreadFactoryC2541 implements ThreadFactory {

        /* renamed from: ʬ  reason: contains not printable characters */
        public final /* synthetic */ boolean f8577;

        /* renamed from: ῲ  reason: contains not printable characters */
        public final /* synthetic */ String f8578;

        public ThreadFactoryC2541(String str, boolean z) {
            this.f8578 = str;
            this.f8577 = z;
        }

        public Thread newThread(Runnable runnable) {
            Thread thread = new Thread(runnable, this.f8578);
            thread.setDaemon(this.f8577);
            return thread;
        }
    }

    /* renamed from: 㿎.ሽ.ʬ$K  reason: contains not printable characters */
    /* compiled from: Util */
    public class C2542 implements Comparator<String> {
        /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object, java.lang.Object] */
        @Override // java.util.Comparator
        public int compare(String str, String str2) {
            return str.compareTo(str2);
        }
    }

    static {
        Method method = null;
        AbstractC2651.create((C2628) null, f8569);
        Charset.forName(Encoder.DEFAULT_BYTE_MODE_ENCODING);
        try {
            method = Throwable.class.getDeclaredMethod("addSuppressed", Throwable.class);
        } catch (Exception unused) {
        }
        f8562 = method;
    }

    /* renamed from: ʬ  reason: contains not printable characters */
    public static int m6629(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;
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public static boolean m6634(AbstractC1494 r11, int i, TimeUnit timeUnit) throws IOException {
        long nanoTime = System.nanoTime();
        long r5 = r11.timeout().m3706() ? r11.timeout().m3700() - nanoTime : Long.MAX_VALUE;
        r11.timeout().m3704(Math.min(r5, timeUnit.toNanos((long) i)) + nanoTime);
        try {
            C1492 r12 = new C1492();
            while (r11.read(r12, PlaybackStateCompat.ACTION_PLAY_FROM_URI) != -1) {
                r12.m3773();
            }
            if (r5 == RecyclerView.FOREVER_NS) {
                r11.timeout().m3703();
            } else {
                r11.timeout().m3704(nanoTime + r5);
            }
            return true;
        } catch (InterruptedIOException unused) {
            if (r5 == RecyclerView.FOREVER_NS) {
                r11.timeout().m3703();
            } else {
                r11.timeout().m3704(nanoTime + r5);
            }
            return false;
        } catch (Throwable th) {
            if (r5 == RecyclerView.FOREVER_NS) {
                r11.timeout().m3703();
            } else {
                r11.timeout().m3704(nanoTime + r5);
            }
            throw th;
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public static int m6635(char c) {
        if (c >= '0' && c <= '9') {
            return c - '0';
        }
        char c2 = 'a';
        if (c < 'a' || c > 'f') {
            c2 = 'A';
            if (c < 'A' || c > 'F') {
                return -1;
            }
        }
        return (c - c2) + 10;
    }

    /* renamed from: K  reason: contains not printable characters */
    public static void m6650(long j, long j2, long j3) {
        if ((j2 | j3) < 0 || j2 > j || j - j2 < j3) {
            throw new ArrayIndexOutOfBoundsException();
        }
    }

    /* renamed from: 㸾  reason: contains not printable characters */
    public static String m6657(String str, int i, int i2) {
        int r1 = m6632(str, i, i2);
        return str.substring(r1, m6629(str, r1, i2));
    }

    /* renamed from: ʬ  reason: contains not printable characters */
    public static boolean m6630(String str) {
        return f8564.matcher(str).matches();
    }

    /* renamed from: K  reason: contains not printable characters */
    public static boolean m6654(Object obj, Object obj2) {
        return obj == obj2 || (obj != null && obj.equals(obj2));
    }

    /* renamed from: K  reason: contains not printable characters */
    public static void m6651(Closeable closeable) {
        if (closeable != null) {
            try {
                closeable.close();
            } catch (RuntimeException e) {
                throw e;
            } catch (Exception unused) {
            }
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public static void m6652(Socket socket) {
        if (socket != null) {
            try {
                socket.close();
            } catch (AssertionError e) {
                if (!m6653(e)) {
                    throw e;
                }
            } catch (RuntimeException e2) {
                throw e2;
            } catch (Exception unused) {
            }
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public static boolean m6655(AbstractC1494 r0, int i, TimeUnit timeUnit) {
        try {
            return m6634(r0, i, timeUnit);
        } catch (IOException unused) {
            return false;
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public static <T> List<T> m6646(List<T> list) {
        return Collections.unmodifiableList(new ArrayList(list));
    }

    /* renamed from: K  reason: contains not printable characters */
    public static <K, V> Map<K, V> m6648(Map<K, V> map) {
        if (map.isEmpty()) {
            return Collections.emptyMap();
        }
        return Collections.unmodifiableMap(new LinkedHashMap(map));
    }

    /* renamed from: K  reason: contains not printable characters */
    public static <T> List<T> m6647(T... tArr) {
        return Collections.unmodifiableList(Arrays.asList((Object[]) tArr.clone()));
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public static boolean m6633(Comparator<String> 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;
    }

    /* renamed from: K  reason: contains not printable characters */
    public static ThreadFactory m6649(String str, boolean z) {
        return new ThreadFactoryC2541(str, z);
    }

    /* renamed from: K  reason: contains not printable characters */
    public static String[] m6656(Comparator<? super String> 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;
                } else if (comparator.compare(str, strArr2[i]) == 0) {
                    arrayList.add(str);
                    break;
                } else {
                    i++;
                }
            }
        }
        return (String[]) arrayList.toArray(new String[arrayList.size()]);
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public static int m6632(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;
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public static int m6631(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;
    }

    /* renamed from: K  reason: contains not printable characters */
    public static boolean m6653(AssertionError assertionError) {
        return (assertionError.getCause() == null || assertionError.getMessage() == null || !assertionError.getMessage().contains("getsockname failed")) ? false : true;
    }

    /* renamed from: K  reason: contains not printable characters */
    public static int m6639(Comparator<String> 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;
    }

    /* renamed from: K  reason: contains not printable characters */
    public static int m6637(String str, int i, int i2, String str2) {
        while (i < i2) {
            if (str2.indexOf(str.charAt(i)) != -1) {
                return i;
            }
            i++;
        }
        return i2;
    }

    /* renamed from: K  reason: contains not printable characters */
    public static int m6636(String str, int i, int i2, char c) {
        while (i < i2) {
            if (str.charAt(i) == c) {
                return i;
            }
            i++;
        }
        return i2;
    }

    /* renamed from: K  reason: contains not printable characters */
    public static String m6641(String str) {
        InetAddress inetAddress;
        int i = -1;
        boolean z = true;
        int i2 = 0;
        if (str.contains(CertificateUtil.DELIMITER)) {
            if (!str.startsWith("[") || !str.endsWith("]")) {
                inetAddress = m6644(str, 0, str.length());
            } else {
                inetAddress = m6644(str, 1, str.length() - 1);
            }
            if (inetAddress == null) {
                return null;
            }
            byte[] address = inetAddress.getAddress();
            if (address.length == 16) {
                int i3 = 0;
                int i4 = 0;
                while (i3 < address.length) {
                    int i5 = i3;
                    while (i5 < 16 && address[i5] == 0 && address[i5 + 1] == 0) {
                        i5 += 2;
                    }
                    int i6 = i5 - i3;
                    if (i6 > i4 && i6 >= 4) {
                        i = i3;
                        i4 = i6;
                    }
                    i3 = i5 + 2;
                }
                C1492 r8 = new C1492();
                while (i2 < address.length) {
                    if (i2 == i) {
                        r8.writeByte(58);
                        i2 += i4;
                        if (i2 == 16) {
                            r8.writeByte(58);
                        }
                    } else {
                        if (i2 > 0) {
                            r8.writeByte(58);
                        }
                        r8.m3791((long) (((address[i2] & 255) << 8) | (address[i2 + 1] & 255)));
                        i2 += 2;
                    }
                }
                return r8.m3800();
            }
            throw new AssertionError(C1293.m3413("Invalid IPv6 address: '", str, "'"));
        }
        try {
            String lowerCase = IDN.toASCII(str).toLowerCase(Locale.US);
            if (lowerCase.isEmpty()) {
                return null;
            }
            int i7 = 0;
            while (true) {
                if (i7 >= lowerCase.length()) {
                    z = false;
                    break;
                }
                char charAt = lowerCase.charAt(i7);
                if (charAt <= 31) {
                    break;
                } else if (charAt >= 127) {
                    break;
                } else if (" #%/:?@[\\]".indexOf(charAt) != -1) {
                    break;
                } else {
                    i7++;
                }
            }
            if (z) {
                return null;
            }
            return lowerCase;
        } catch (IllegalArgumentException unused) {
            return null;
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public static String m6642(String str, Object... objArr) {
        return String.format(Locale.US, str, objArr);
    }

    /* renamed from: K  reason: contains not printable characters */
    public static Charset m6645(AbstractC1496 r3, Charset charset) throws IOException {
        if (r3.m3820(0, f8574)) {
            r3.skip((long) f8574.size());
            return f8566;
        } else if (r3.m3820(0, f8563)) {
            r3.skip((long) f8563.size());
            return f8572;
        } else if (r3.m3820(0, f8573)) {
            r3.skip((long) f8573.size());
            return f8565;
        } else if (r3.m3820(0, f8568)) {
            r3.skip((long) f8568.size());
            return f8570;
        } else if (!r3.m3820(0, f8575)) {
            return charset;
        } else {
            r3.skip((long) f8575.size());
            return f8576;
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public static String m6643(C2531 r4, boolean z) {
        String str;
        if (r4.f8542.contains(CertificateUtil.DELIMITER)) {
            str = C1293.m3414(C1293.m3416("["), r4.f8542, "]");
        } else {
            str = r4.f8542;
        }
        if (!z && r4.f8536 == C2531.m6584(r4.f8540)) {
            return str;
        }
        StringBuilder r5 = C1293.m3402(str, CertificateUtil.DELIMITER);
        r5.append(r4.f8536);
        return r5.toString();
    }

    /* renamed from: K  reason: contains not printable characters */
    public static int m6638(String str, long j, TimeUnit timeUnit) {
        int i = (j > 0 ? 1 : (j == 0 ? 0 : -1));
        if (i < 0) {
            throw new IllegalArgumentException(C1293.m3412(str, " < 0"));
        } else if (timeUnit != null) {
            long millis = timeUnit.toMillis(j);
            if (millis > 2147483647L) {
                throw new IllegalArgumentException(C1293.m3412(str, " too large."));
            } else if (millis != 0 || i <= 0) {
                return (int) millis;
            } else {
                throw new IllegalArgumentException(C1293.m3412(str, " too small."));
            }
        } else {
            throw new NullPointerException("unit == null");
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public static AssertionError m6640(String str, Exception exc) {
        AssertionError assertionError = new AssertionError(str);
        try {
            assertionError.initCause(exc);
        } catch (IllegalStateException unused) {
        }
        return assertionError;
    }

    /* JADX WARNING: Code restructure failed: missing block: B:45:0x0096, code lost:
        r4 = 0;
     */
    /* renamed from: K  reason: contains not printable characters */
    public static InetAddress m6644(String str, int i, int i2) {
        byte[] bArr = new byte[16];
        int i3 = -1;
        int i4 = 0;
        int i5 = i;
        int i6 = 0;
        int i7 = -1;
        int i8 = -1;
        while (true) {
            if (i5 >= i2) {
                break;
            } else if (i6 == bArr.length) {
                return null;
            } else {
                int i9 = i5 + 2;
                if (i9 > i2 || !str.regionMatches(i5, "::", i4, 2)) {
                    if (i6 != 0) {
                        if (str.regionMatches(i5, CertificateUtil.DELIMITER, i4, 1)) {
                            i5++;
                        } else if (!str.regionMatches(i5, CodelessMatcher.CURRENT_CLASS_NAME, i4, 1)) {
                            return null;
                        } else {
                            int i10 = i6 - 2;
                            int i11 = i10;
                            loop1:
                            while (true) {
                                if (i8 < i2) {
                                    if (i11 == bArr.length) {
                                        break;
                                    }
                                    if (i11 != i10) {
                                        if (str.charAt(i8) != '.') {
                                            break;
                                        }
                                        i8++;
                                    }
                                    int i12 = i8;
                                    int i13 = 0;
                                    while (true) {
                                        if (i12 < i2) {
                                            char charAt = str.charAt(i12);
                                            if (charAt >= '0' && charAt <= '9') {
                                                if ((i13 == 0 && i8 != i12) || (i13 = ((i13 * 10) + charAt) - 48) > 255) {
                                                    break loop1;
                                                }
                                                i12++;
                                            } else {
                                                break;
                                            }
                                        } else {
                                            break;
                                        }
                                    }
                                    if (i12 - i8 == 0) {
                                        break;
                                    }
                                    bArr[i11] = (byte) i13;
                                    i11++;
                                    i8 = i12;
                                    i4 = 0;
                                } else if (i11 == i10 + 4) {
                                    i4 = 1;
                                }
                            }
                            if (i4 == 0) {
                                return null;
                            }
                            i6 += 2;
                        }
                    }
                    i8 = i5;
                } else if (i7 != i3) {
                    return null;
                } else {
                    i6 += 2;
                    i7 = i6;
                    if (i9 == i2) {
                        break;
                    }
                    i8 = i9;
                }
                i5 = i8;
                int i14 = 0;
                while (i5 < i2) {
                    int r4 = m6635(str.charAt(i5));
                    if (r4 == -1) {
                        break;
                    }
                    i14 = (i14 << 4) + r4;
                    i5++;
                }
                int i15 = i5 - i8;
                if (i15 == 0 || i15 > 4) {
                    return null;
                }
                int i16 = i6 + 1;
                bArr[i6] = (byte) ((i14 >>> 8) & BaseProgressIndicator.MAX_ALPHA);
                i6 = i16 + 1;
                bArr[i16] = (byte) (i14 & BaseProgressIndicator.MAX_ALPHA);
                i3 = -1;
                i4 = 0;
            }
        }
        if (i6 != bArr.length) {
            if (i7 == -1) {
                return null;
            }
            int i17 = i6 - i7;
            System.arraycopy(bArr, i7, bArr, bArr.length - i17, i17);
            Arrays.fill(bArr, i7, (bArr.length - i6) + i7, (byte) 0);
        }
        try {
            return InetAddress.getByAddress(bArr);
        } catch (UnknownHostException unused) {
            throw new AssertionError();
        }
    }
}
