package okhttp3.internal;

import d.b.a.a.a;
import g.a0;
import g.c0.g;
import g.c0.m;
import g.h0.c.f0;
import g.h0.c.l;
import g.m0.c;
import g.m0.f;
import j.b0;
import j.d;
import j.h;
import j.r;
import j.z;
import java.io.Closeable;
import java.io.EOFException;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.SocketTimeoutException;
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.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.TimeZone;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import jxl.SheetSettings;
import okhttp3.Call;
import okhttp3.EventListener;
import okhttp3.Headers;
import okhttp3.HttpUrl;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.ResponseBody;
import okhttp3.internal.http2.Header;
import okhttp3.internal.io.FileSystem;

/* JADX INFO: compiled from: Util.kt */
/* JADX INFO: loaded from: classes.dex */
public final class Util {
    public static final byte[] EMPTY_BYTE_ARRAY;
    public static final Headers EMPTY_HEADERS = Headers.Companion.of(new String[0]);
    public static final RequestBody EMPTY_REQUEST;
    public static final ResponseBody EMPTY_RESPONSE;
    private static final r UNICODE_BOMS;
    public static final TimeZone UTC;
    private static final c VERIFY_AS_IP_ADDRESS;
    public static final boolean assertionsEnabled;
    public static final String okHttpName;
    public static final String userAgent = "okhttp/4.9.1";

    static {
        byte[] bArr = new byte[0];
        EMPTY_BYTE_ARRAY = bArr;
        EMPTY_RESPONSE = ResponseBody.Companion.create$default(ResponseBody.Companion, bArr, (MediaType) null, 1, (Object) null);
        EMPTY_REQUEST = RequestBody.Companion.create$default(RequestBody.Companion, bArr, (MediaType) null, 0, 0, 7, (Object) null);
        r.a aVar = r.f4631b;
        h.a aVar2 = h.f4612e;
        UNICODE_BOMS = aVar.c(aVar2.b("efbbbf"), aVar2.b("feff"), aVar2.b("fffe"), aVar2.b("0000ffff"), aVar2.b("ffff0000"));
        TimeZone timeZone = TimeZone.getTimeZone("GMT");
        l.c(timeZone);
        UTC = timeZone;
        VERIFY_AS_IP_ADDRESS = new c("([0-9a-fA-F]*:[0-9a-fA-F:.]*)|([\\d.]+)");
        assertionsEnabled = false;
        String name = OkHttpClient.class.getName();
        l.e(name, "OkHttpClient::class.java.name");
        String strY = f.y(name, "okhttp3.");
        l.f(strY, "<this>");
        l.f("Client", "suffix");
        if (f.c(strY, "Client", false, 2)) {
            strY = strY.substring(0, strY.length() - "Client".length());
            l.e(strY, "this as java.lang.String…ing(startIndex, endIndex)");
        }
        okHttpName = strY;
    }

    public static final <E> void addIfAbsent(List<E> list, E e2) {
        l.f(list, "$this$addIfAbsent");
        if (list.contains(e2)) {
            return;
        }
        list.add(e2);
    }

    public static final int and(byte b2, int i2) {
        return b2 & i2;
    }

    public static final int and(short s, int i2) {
        return s & i2;
    }

    public static final long and(int i2, long j2) {
        return ((long) i2) & j2;
    }

    public static final EventListener.Factory asFactory(final EventListener eventListener) {
        l.f(eventListener, "$this$asFactory");
        return new EventListener.Factory() { // from class: okhttp3.internal.Util.asFactory.1
            @Override // okhttp3.EventListener.Factory
            public final EventListener create(Call call) {
                l.f(call, "it");
                return eventListener;
            }
        };
    }

    public static final void assertThreadDoesntHoldLock(Object obj) {
        l.f(obj, "$this$assertThreadDoesntHoldLock");
        if (assertionsEnabled && Thread.holdsLock(obj)) {
            StringBuilder sbB = a.B("Thread ");
            Thread threadCurrentThread = Thread.currentThread();
            l.e(threadCurrentThread, "Thread.currentThread()");
            sbB.append(threadCurrentThread.getName());
            sbB.append(" MUST NOT hold lock on ");
            sbB.append(obj);
            throw new AssertionError(sbB.toString());
        }
    }

    public static final void assertThreadHoldsLock(Object obj) {
        l.f(obj, "$this$assertThreadHoldsLock");
        if (!assertionsEnabled || Thread.holdsLock(obj)) {
            return;
        }
        StringBuilder sbB = a.B("Thread ");
        Thread threadCurrentThread = Thread.currentThread();
        l.e(threadCurrentThread, "Thread.currentThread()");
        sbB.append(threadCurrentThread.getName());
        sbB.append(" MUST hold lock on ");
        sbB.append(obj);
        throw new AssertionError(sbB.toString());
    }

    public static final boolean canParseAsIpAddress(String str) {
        l.f(str, "$this$canParseAsIpAddress");
        return VERIFY_AS_IP_ADDRESS.a(str);
    }

    public static final boolean canReuseConnectionFor(HttpUrl httpUrl, HttpUrl httpUrl2) {
        l.f(httpUrl, "$this$canReuseConnectionFor");
        l.f(httpUrl2, "other");
        return l.a(httpUrl.host(), httpUrl2.host()) && httpUrl.port() == httpUrl2.port() && l.a(httpUrl.scheme(), httpUrl2.scheme());
    }

    public static final int checkDuration(String str, long j2, TimeUnit timeUnit) {
        l.f(str, "name");
        boolean z = true;
        if (!(j2 >= 0)) {
            throw new IllegalStateException(a.p(str, " < 0").toString());
        }
        if (!(timeUnit != null)) {
            throw new IllegalStateException("unit == null".toString());
        }
        long millis = timeUnit.toMillis(j2);
        if (!(millis <= ((long) Integer.MAX_VALUE))) {
            throw new IllegalArgumentException(a.p(str, " too large.").toString());
        }
        if (millis == 0 && j2 > 0) {
            z = false;
        }
        if (z) {
            return (int) millis;
        }
        throw new IllegalArgumentException(a.p(str, " too small.").toString());
    }

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

    public static final void closeQuietly(Closeable closeable) {
        l.f(closeable, "$this$closeQuietly");
        try {
            closeable.close();
        } catch (RuntimeException e2) {
            throw e2;
        } catch (Exception unused) {
        }
    }

    public static final String[] concat(String[] strArr, String str) {
        l.f(strArr, "$this$concat");
        l.f(str, "value");
        Object[] objArrCopyOf = Arrays.copyOf(strArr, strArr.length + 1);
        l.e(objArrCopyOf, "java.util.Arrays.copyOf(this, newSize)");
        String[] strArr2 = (String[]) objArrCopyOf;
        strArr2[f.a.y.a.f0(strArr2)] = str;
        return strArr2;
    }

    public static final int delimiterOffset(String str, String str2, int i2, int i3) {
        l.f(str, "$this$delimiterOffset");
        l.f(str2, "delimiters");
        while (i2 < i3) {
            if (f.a(str2, str.charAt(i2), false, 2)) {
                return i2;
            }
            i2++;
        }
        return i3;
    }

    public static /* synthetic */ int delimiterOffset$default(String str, String str2, int i2, int i3, int i4, Object obj) {
        if ((i4 & 2) != 0) {
            i2 = 0;
        }
        if ((i4 & 4) != 0) {
            i3 = str.length();
        }
        return delimiterOffset(str, str2, i2, i3);
    }

    public static final boolean discard(b0 b0Var, int i2, TimeUnit timeUnit) {
        l.f(b0Var, "$this$discard");
        l.f(timeUnit, "timeUnit");
        try {
            return skipAll(b0Var, i2, timeUnit);
        } catch (IOException unused) {
            return false;
        }
    }

    public static final <T> List<T> filterList(Iterable<? extends T> iterable, g.h0.b.l<? super T, Boolean> lVar) {
        l.f(iterable, "$this$filterList");
        l.f(lVar, "predicate");
        ArrayList arrayList = g.c0.l.f4067b;
        for (T t : iterable) {
            if (lVar.invoke(t).booleanValue()) {
                if (arrayList.isEmpty()) {
                    arrayList = new ArrayList();
                }
                f0.a(arrayList).add(t);
            }
        }
        return arrayList;
    }

    public static final String format(String str, Object... objArr) {
        l.f(str, "format");
        l.f(objArr, "args");
        Locale locale = Locale.US;
        Object[] objArrCopyOf = Arrays.copyOf(objArr, objArr.length);
        String str2 = String.format(locale, str, Arrays.copyOf(objArrCopyOf, objArrCopyOf.length));
        l.e(str2, "java.lang.String.format(locale, format, *args)");
        return str2;
    }

    public static final boolean hasIntersection(String[] strArr, String[] strArr2, Comparator<? super String> comparator) {
        l.f(strArr, "$this$hasIntersection");
        l.f(comparator, "comparator");
        if (!(strArr.length == 0) && strArr2 != null) {
            if (!(strArr2.length == 0)) {
                for (String str : strArr) {
                    for (String str2 : strArr2) {
                        if (comparator.compare(str, str2) == 0) {
                            return true;
                        }
                    }
                }
            }
        }
        return false;
    }

    public static final long headersContentLength(Response response) {
        l.f(response, "$this$headersContentLength");
        String str = response.headers().get("Content-Length");
        if (str != null) {
            return toLongOrDefault(str, -1L);
        }
        return -1L;
    }

    public static final void ignoreIoExceptions(g.h0.b.a<a0> aVar) {
        l.f(aVar, "block");
        try {
            aVar.invoke();
        } catch (IOException unused) {
        }
    }

    @SafeVarargs
    public static final <T> List<T> immutableListOf(T... tArr) {
        l.f(tArr, "elements");
        Object[] objArr = (Object[]) tArr.clone();
        List<T> listUnmodifiableList = Collections.unmodifiableList(g.u(Arrays.copyOf(objArr, objArr.length)));
        l.e(listUnmodifiableList, "Collections.unmodifiable…istOf(*elements.clone()))");
        return listUnmodifiableList;
    }

    public static final int indexOf(String[] strArr, String str, Comparator<String> comparator) {
        l.f(strArr, "$this$indexOf");
        l.f(str, "value");
        l.f(comparator, "comparator");
        int length = strArr.length;
        for (int i2 = 0; i2 < length; i2++) {
            if (comparator.compare(strArr[i2], str) == 0) {
                return i2;
            }
        }
        return -1;
    }

    public static final int indexOfControlOrNonAscii(String str) {
        l.f(str, "$this$indexOfControlOrNonAscii");
        int length = str.length();
        for (int i2 = 0; i2 < length; i2++) {
            char cCharAt = str.charAt(i2);
            if (l.h(cCharAt, 31) <= 0 || l.h(cCharAt, 127) >= 0) {
                return i2;
            }
        }
        return -1;
    }

    public static final int indexOfFirstNonAsciiWhitespace(String str, int i2, int i3) {
        l.f(str, "$this$indexOfFirstNonAsciiWhitespace");
        while (i2 < i3) {
            char cCharAt = str.charAt(i2);
            if (cCharAt != '\t' && cCharAt != '\n' && cCharAt != '\f' && cCharAt != '\r' && cCharAt != ' ') {
                return i2;
            }
            i2++;
        }
        return i3;
    }

    public static /* synthetic */ int indexOfFirstNonAsciiWhitespace$default(String str, int i2, int i3, int i4, Object obj) {
        if ((i4 & 1) != 0) {
            i2 = 0;
        }
        if ((i4 & 2) != 0) {
            i3 = str.length();
        }
        return indexOfFirstNonAsciiWhitespace(str, i2, i3);
    }

    public static final int indexOfLastNonAsciiWhitespace(String str, int i2, int i3) {
        l.f(str, "$this$indexOfLastNonAsciiWhitespace");
        int i4 = i3 - 1;
        if (i4 >= i2) {
            while (true) {
                char cCharAt = str.charAt(i4);
                if (cCharAt != '\t' && cCharAt != '\n' && cCharAt != '\f' && cCharAt != '\r' && cCharAt != ' ') {
                    return i4 + 1;
                }
                if (i4 == i2) {
                    break;
                }
                i4--;
            }
        }
        return i2;
    }

    public static /* synthetic */ int indexOfLastNonAsciiWhitespace$default(String str, int i2, int i3, int i4, Object obj) {
        if ((i4 & 1) != 0) {
            i2 = 0;
        }
        if ((i4 & 2) != 0) {
            i3 = str.length();
        }
        return indexOfLastNonAsciiWhitespace(str, i2, i3);
    }

    public static final int indexOfNonWhitespace(String str, int i2) {
        l.f(str, "$this$indexOfNonWhitespace");
        int length = str.length();
        while (i2 < length) {
            char cCharAt = str.charAt(i2);
            if (cCharAt != ' ' && cCharAt != '\t') {
                return i2;
            }
            i2++;
        }
        return str.length();
    }

    public static /* synthetic */ int indexOfNonWhitespace$default(String str, int i2, int i3, Object obj) {
        if ((i3 & 1) != 0) {
            i2 = 0;
        }
        return indexOfNonWhitespace(str, i2);
    }

    public static final String[] intersect(String[] strArr, String[] strArr2, Comparator<? super String> comparator) {
        l.f(strArr, "$this$intersect");
        l.f(strArr2, "other");
        l.f(comparator, "comparator");
        ArrayList arrayList = new ArrayList();
        for (String str : strArr) {
            int length = strArr2.length;
            int i2 = 0;
            while (true) {
                if (i2 >= length) {
                    break;
                }
                if (comparator.compare(str, strArr2[i2]) == 0) {
                    arrayList.add(str);
                    break;
                }
                i2++;
            }
        }
        Object[] array = arrayList.toArray(new String[0]);
        Objects.requireNonNull(array, "null cannot be cast to non-null type kotlin.Array<T>");
        return (String[]) array;
    }

    public static final boolean isCivilized(FileSystem fileSystem, File file) throws IOException {
        l.f(fileSystem, "$this$isCivilized");
        l.f(file, "file");
        z zVarSink = fileSystem.sink(file);
        try {
            fileSystem.delete(file);
            f.a.y.a.B(zVarSink, null);
            return true;
        } catch (IOException unused) {
            f.a.y.a.B(zVarSink, null);
            fileSystem.delete(file);
            return false;
        } catch (Throwable th) {
            try {
                throw th;
            } catch (Throwable th2) {
                f.a.y.a.B(zVarSink, th);
                throw th2;
            }
        }
    }

    public static final boolean isHealthy(Socket socket, j.g gVar) {
        l.f(socket, "$this$isHealthy");
        l.f(gVar, "source");
        try {
            int soTimeout = socket.getSoTimeout();
            try {
                socket.setSoTimeout(1);
                boolean z = !gVar.n();
                socket.setSoTimeout(soTimeout);
                return z;
            } catch (Throwable th) {
                socket.setSoTimeout(soTimeout);
                throw th;
            }
        } catch (SocketTimeoutException unused) {
            return true;
        } catch (IOException unused2) {
            return false;
        }
    }

    public static final void notify(Object obj) {
        l.f(obj, "$this$notify");
        obj.notify();
    }

    public static final void notifyAll(Object obj) {
        l.f(obj, "$this$notifyAll");
        obj.notifyAll();
    }

    public static final int parseHexDigit(char c2) {
        if ('0' <= c2 && '9' >= c2) {
            return c2 - '0';
        }
        char c3 = 'a';
        if ('a' > c2 || 'f' < c2) {
            c3 = 'A';
            if ('A' > c2 || 'F' < c2) {
                return -1;
            }
        }
        return (c2 - c3) + 10;
    }

    public static final String peerName(Socket socket) {
        l.f(socket, "$this$peerName");
        SocketAddress remoteSocketAddress = socket.getRemoteSocketAddress();
        if (!(remoteSocketAddress instanceof InetSocketAddress)) {
            return remoteSocketAddress.toString();
        }
        String hostName = ((InetSocketAddress) remoteSocketAddress).getHostName();
        l.e(hostName, "address.hostName");
        return hostName;
    }

    public static final Charset readBomAsCharset(j.g gVar, Charset charset) throws IOException {
        Charset charsetForName;
        l.f(gVar, "$this$readBomAsCharset");
        l.f(charset, "default");
        int iK0 = gVar.k0(UNICODE_BOMS);
        if (iK0 == -1) {
            return charset;
        }
        if (iK0 == 0) {
            Charset charset2 = StandardCharsets.UTF_8;
            l.e(charset2, "UTF_8");
            return charset2;
        }
        if (iK0 == 1) {
            Charset charset3 = StandardCharsets.UTF_16BE;
            l.e(charset3, "UTF_16BE");
            return charset3;
        }
        if (iK0 == 2) {
            Charset charset4 = StandardCharsets.UTF_16LE;
            l.e(charset4, "UTF_16LE");
            return charset4;
        }
        if (iK0 == 3) {
            g.m0.a aVar = g.m0.a.a;
            charsetForName = g.m0.a.f4158d;
            if (charsetForName == null) {
                charsetForName = Charset.forName("UTF-32BE");
                l.e(charsetForName, "forName(\"UTF-32BE\")");
                g.m0.a.f4158d = charsetForName;
            }
        } else {
            if (iK0 != 4) {
                throw new AssertionError();
            }
            g.m0.a aVar2 = g.m0.a.a;
            charsetForName = g.m0.a.f4157c;
            if (charsetForName == null) {
                charsetForName = Charset.forName("UTF-32LE");
                l.e(charsetForName, "forName(\"UTF-32LE\")");
                g.m0.a.f4157c = charsetForName;
            }
        }
        return charsetForName;
    }

    public static final <T> T readFieldOrNull(Object obj, Class<T> cls, String str) {
        T tCast;
        Object fieldOrNull;
        l.f(obj, "instance");
        l.f(cls, "fieldType");
        l.f(str, "fieldName");
        Class<?> superclass = obj.getClass();
        while (true) {
            tCast = null;
            if (!(!l.a(superclass, Object.class))) {
                if (!(!l.a(str, "delegate")) || (fieldOrNull = readFieldOrNull(obj, Object.class, "delegate")) == null) {
                    return null;
                }
                return (T) readFieldOrNull(fieldOrNull, cls, str);
            }
            try {
                Field declaredField = superclass.getDeclaredField(str);
                l.e(declaredField, "field");
                declaredField.setAccessible(true);
                Object obj2 = declaredField.get(obj);
                if (!cls.isInstance(obj2)) {
                    break;
                }
                tCast = cls.cast(obj2);
                break;
            } catch (NoSuchFieldException unused) {
                superclass = superclass.getSuperclass();
                l.e(superclass, "c.superclass");
            }
        }
        return tCast;
    }

    public static final int readMedium(j.g gVar) throws IOException {
        l.f(gVar, "$this$readMedium");
        return and(gVar.F(), SheetSettings.DEFAULT_DEFAULT_ROW_HEIGHT) | (and(gVar.F(), SheetSettings.DEFAULT_DEFAULT_ROW_HEIGHT) << 16) | (and(gVar.F(), SheetSettings.DEFAULT_DEFAULT_ROW_HEIGHT) << 8);
    }

    /* JADX WARN: Removed duplicated region for block: B:15:0x005d A[PHI: r12
      0x005d: PHI (r12v6 boolean) = (r12v5 boolean), (r12v10 boolean) binds: [B:23:0x007f, B:13:0x0053] A[DONT_GENERATE, DONT_INLINE]] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public static final boolean skipAll(j.b0 r11, int r12, java.util.concurrent.TimeUnit r13) throws java.io.IOException {
        /*
            java.lang.String r0 = "$this$skipAll"
            g.h0.c.l.f(r11, r0)
            java.lang.String r0 = "timeUnit"
            g.h0.c.l.f(r13, r0)
            long r0 = java.lang.System.nanoTime()
            j.c0 r2 = r11.timeout()
            boolean r2 = r2.hasDeadline()
            r3 = 9223372036854775807(0x7fffffffffffffff, double:NaN)
            if (r2 == 0) goto L27
            j.c0 r2 = r11.timeout()
            long r5 = r2.deadlineNanoTime()
            long r5 = r5 - r0
            goto L28
        L27:
            r5 = r3
        L28:
            j.c0 r2 = r11.timeout()
            long r7 = (long) r12
            long r12 = r13.toNanos(r7)
            long r12 = java.lang.Math.min(r5, r12)
            long r12 = r12 + r0
            r2.deadlineNanoTime(r12)
            j.d r12 = new j.d     // Catch: java.lang.Throwable -> L66 java.io.InterruptedIOException -> L7c
            r12.<init>()     // Catch: java.lang.Throwable -> L66 java.io.InterruptedIOException -> L7c
        L3e:
            r7 = 8192(0x2000, double:4.0474E-320)
            long r7 = r11.read(r12, r7)     // Catch: java.lang.Throwable -> L66 java.io.InterruptedIOException -> L7c
            r9 = -1
            int r13 = (r7 > r9 ? 1 : (r7 == r9 ? 0 : -1))
            if (r13 == 0) goto L50
            long r7 = r12.f4601e     // Catch: java.lang.Throwable -> L66 java.io.InterruptedIOException -> L7c
            r12.K(r7)     // Catch: java.lang.Throwable -> L66 java.io.InterruptedIOException -> L7c
            goto L3e
        L50:
            r12 = 1
            int r13 = (r5 > r3 ? 1 : (r5 == r3 ? 0 : -1))
            if (r13 != 0) goto L5d
        L55:
            j.c0 r11 = r11.timeout()
            r11.clearDeadline()
            goto L82
        L5d:
            j.c0 r11 = r11.timeout()
            long r0 = r0 + r5
            r11.deadlineNanoTime(r0)
            goto L82
        L66:
            r12 = move-exception
            int r13 = (r5 > r3 ? 1 : (r5 == r3 ? 0 : -1))
            if (r13 != 0) goto L73
            j.c0 r11 = r11.timeout()
            r11.clearDeadline()
            goto L7b
        L73:
            j.c0 r11 = r11.timeout()
            long r0 = r0 + r5
            r11.deadlineNanoTime(r0)
        L7b:
            throw r12
        L7c:
            r12 = 0
            int r13 = (r5 > r3 ? 1 : (r5 == r3 ? 0 : -1))
            if (r13 != 0) goto L5d
            goto L55
        L82:
            return r12
        */
        throw new UnsupportedOperationException("Method not decompiled: okhttp3.internal.Util.skipAll(j.b0, int, java.util.concurrent.TimeUnit):boolean");
    }

    public static final ThreadFactory threadFactory(final String str, final boolean z) {
        l.f(str, "name");
        return new ThreadFactory() { // from class: okhttp3.internal.Util.threadFactory.1
            @Override // java.util.concurrent.ThreadFactory
            public final Thread newThread(Runnable runnable) {
                Thread thread = new Thread(runnable, str);
                thread.setDaemon(z);
                return thread;
            }
        };
    }

    public static final void threadName(String str, g.h0.b.a<a0> aVar) {
        l.f(str, "name");
        l.f(aVar, "block");
        Thread threadCurrentThread = Thread.currentThread();
        l.e(threadCurrentThread, "currentThread");
        String name = threadCurrentThread.getName();
        threadCurrentThread.setName(str);
        try {
            aVar.invoke();
        } finally {
            threadCurrentThread.setName(name);
        }
    }

    public static final List<Header> toHeaderList(Headers headers) {
        l.f(headers, "$this$toHeaderList");
        g.j0.h hVarD = g.j0.l.d(0, headers.size());
        ArrayList arrayList = new ArrayList(f.a.y.a.C(hVarD, 10));
        Iterator<Integer> it = hVarD.iterator();
        while (it.hasNext()) {
            int iB = ((g.c0.r) it).b();
            arrayList.add(new Header(headers.name(iB), headers.value(iB)));
        }
        return arrayList;
    }

    public static final Headers toHeaders(List<Header> list) {
        l.f(list, "$this$toHeaders");
        Headers.Builder builder = new Headers.Builder();
        for (Header header : list) {
            builder.addLenient$okhttp(header.component1().l(), header.component2().l());
        }
        return builder.build();
    }

    public static final String toHexString(long j2) {
        String hexString = Long.toHexString(j2);
        l.e(hexString, "java.lang.Long.toHexString(this)");
        return hexString;
    }

    public static final String toHostHeader(HttpUrl httpUrl, boolean z) {
        String strHost;
        l.f(httpUrl, "$this$toHostHeader");
        if (f.b(httpUrl.host(), ":", false, 2)) {
            strHost = '[' + httpUrl.host() + ']';
        } else {
            strHost = httpUrl.host();
        }
        if (!z && httpUrl.port() == HttpUrl.Companion.defaultPort(httpUrl.scheme())) {
            return strHost;
        }
        return strHost + ':' + httpUrl.port();
    }

    public static /* synthetic */ String toHostHeader$default(HttpUrl httpUrl, boolean z, int i2, Object obj) {
        if ((i2 & 1) != 0) {
            z = false;
        }
        return toHostHeader(httpUrl, z);
    }

    public static final <T> List<T> toImmutableList(List<? extends T> list) {
        l.f(list, "$this$toImmutableList");
        List<T> listUnmodifiableList = Collections.unmodifiableList(g.K(list));
        l.e(listUnmodifiableList, "Collections.unmodifiableList(toMutableList())");
        return listUnmodifiableList;
    }

    public static final <K, V> Map<K, V> toImmutableMap(Map<K, ? extends V> map) {
        l.f(map, "$this$toImmutableMap");
        if (map.isEmpty()) {
            g.i();
            return m.f4068b;
        }
        Map<K, V> mapUnmodifiableMap = Collections.unmodifiableMap(new LinkedHashMap(map));
        l.e(mapUnmodifiableMap, "Collections.unmodifiableMap(LinkedHashMap(this))");
        return mapUnmodifiableMap;
    }

    public static final long toLongOrDefault(String str, long j2) {
        l.f(str, "$this$toLongOrDefault");
        try {
            return Long.parseLong(str);
        } catch (NumberFormatException unused) {
            return j2;
        }
    }

    public static final int toNonNegativeInt(String str, int i2) {
        if (str != null) {
            try {
                long j2 = Long.parseLong(str);
                if (j2 > Integer.MAX_VALUE) {
                    return Integer.MAX_VALUE;
                }
                if (j2 < 0) {
                    return 0;
                }
                return (int) j2;
            } catch (NumberFormatException unused) {
            }
        }
        return i2;
    }

    public static final String trimSubstring(String str, int i2, int i3) {
        l.f(str, "$this$trimSubstring");
        int iIndexOfFirstNonAsciiWhitespace = indexOfFirstNonAsciiWhitespace(str, i2, i3);
        String strSubstring = str.substring(iIndexOfFirstNonAsciiWhitespace, indexOfLastNonAsciiWhitespace(str, iIndexOfFirstNonAsciiWhitespace, i3));
        l.e(strSubstring, "(this as java.lang.Strin…ing(startIndex, endIndex)");
        return strSubstring;
    }

    public static /* synthetic */ String trimSubstring$default(String str, int i2, int i3, int i4, Object obj) {
        if ((i4 & 1) != 0) {
            i2 = 0;
        }
        if ((i4 & 2) != 0) {
            i3 = str.length();
        }
        return trimSubstring(str, i2, i3);
    }

    public static final void wait(Object obj) throws InterruptedException {
        l.f(obj, "$this$wait");
        obj.wait();
    }

    public static final Throwable withSuppressed(Exception exc, List<? extends Exception> list) {
        l.f(exc, "$this$withSuppressed");
        l.f(list, "suppressed");
        if (list.size() > 1) {
            System.out.println(list);
        }
        Iterator<? extends Exception> it = list.iterator();
        while (it.hasNext()) {
            f.a.y.a.m(exc, it.next());
        }
        return exc;
    }

    public static final void writeMedium(j.f fVar, int i2) throws IOException {
        l.f(fVar, "$this$writeMedium");
        fVar.writeByte((i2 >>> 16) & SheetSettings.DEFAULT_DEFAULT_ROW_HEIGHT);
        fVar.writeByte((i2 >>> 8) & SheetSettings.DEFAULT_DEFAULT_ROW_HEIGHT);
        fVar.writeByte(i2 & SheetSettings.DEFAULT_DEFAULT_ROW_HEIGHT);
    }

    public static final int delimiterOffset(String str, char c2, int i2, int i3) {
        l.f(str, "$this$delimiterOffset");
        while (i2 < i3) {
            if (str.charAt(i2) == c2) {
                return i2;
            }
            i2++;
        }
        return i3;
    }

    public static /* synthetic */ int delimiterOffset$default(String str, char c2, int i2, int i3, int i4, Object obj) {
        if ((i4 & 2) != 0) {
            i2 = 0;
        }
        if ((i4 & 4) != 0) {
            i3 = str.length();
        }
        return delimiterOffset(str, c2, i2, i3);
    }

    public static final String toHexString(int i2) {
        String hexString = Integer.toHexString(i2);
        l.e(hexString, "Integer.toHexString(this)");
        return hexString;
    }

    public static final void closeQuietly(Socket socket) {
        l.f(socket, "$this$closeQuietly");
        try {
            socket.close();
        } catch (AssertionError e2) {
            throw e2;
        } catch (RuntimeException e3) {
            if (!l.a(e3.getMessage(), "bio == null")) {
                throw e3;
            }
        } catch (Exception unused) {
        }
    }

    public static final void closeQuietly(ServerSocket serverSocket) {
        l.f(serverSocket, "$this$closeQuietly");
        try {
            serverSocket.close();
        } catch (RuntimeException e2) {
            throw e2;
        } catch (Exception unused) {
        }
    }

    public static final int skipAll(d dVar, byte b2) throws EOFException {
        l.f(dVar, "$this$skipAll");
        int i2 = 0;
        while (!dVar.n() && dVar.e(0L) == b2) {
            i2++;
            dVar.F();
        }
        return i2;
    }
}
