package io.netty.util.internal;

import com.seewo.libmyousdk.model.DubboResponseInfo;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;

/* JADX INFO: loaded from: classes.dex */
public final class SystemPropertyUtil {
    private static boolean loggedException;
    private static final InternalLogger logger = InternalLoggerFactory.getInstance((Class<?>) SystemPropertyUtil.class);
    private static boolean initializedLogger = true;
    private static final Pattern INTEGER_PATTERN = Pattern.compile("-?[0-9]+");

    private SystemPropertyUtil() {
    }

    public static boolean contains(String str) {
        return get(str) != null;
    }

    public static String get(String str) {
        return get(str, null);
    }

    public static boolean getBoolean(String str, boolean z) {
        String str2 = get(str);
        if (str2 == null) {
            return z;
        }
        String lowerCase = str2.trim().toLowerCase();
        if (lowerCase.isEmpty() || "true".equals(lowerCase) || "yes".equals(lowerCase) || DubboResponseInfo.STATUS_OK.equals(lowerCase)) {
            return true;
        }
        if ("false".equals(lowerCase) || "no".equals(lowerCase) || "0".equals(lowerCase)) {
            return false;
        }
        log("Unable to parse the boolean system property '" + str + "':" + lowerCase + " - using the default value: " + z);
        return z;
    }

    public static int getInt(String str, int i2) {
        String str2 = get(str);
        if (str2 == null) {
            return i2;
        }
        String lowerCase = str2.trim().toLowerCase();
        if (INTEGER_PATTERN.matcher(lowerCase).matches()) {
            try {
                return Integer.parseInt(lowerCase);
            } catch (Exception unused) {
            }
        }
        log("Unable to parse the integer system property '" + str + "':" + lowerCase + " - using the default value: " + i2);
        return i2;
    }

    public static long getLong(String str, long j2) {
        String str2 = get(str);
        if (str2 == null) {
            return j2;
        }
        String lowerCase = str2.trim().toLowerCase();
        if (INTEGER_PATTERN.matcher(lowerCase).matches()) {
            try {
                return Long.parseLong(lowerCase);
            } catch (Exception unused) {
            }
        }
        log("Unable to parse the long integer system property '" + str + "':" + lowerCase + " - using the default value: " + j2);
        return j2;
    }

    private static void log(String str) {
        if (initializedLogger) {
            logger.warn(str);
        } else {
            Logger.getLogger(SystemPropertyUtil.class.getName()).log(Level.WARNING, str);
        }
    }

    public static String get(final String str, String str2) {
        if (str == null) {
            throw new NullPointerException("key");
        }
        if (str.isEmpty()) {
            throw new IllegalArgumentException("key must not be empty.");
        }
        String str3 = null;
        try {
            if (System.getSecurityManager() == null) {
                str = System.getProperty(str);
                str3 = str;
            } else {
                str3 = (String) AccessController.doPrivileged(new PrivilegedAction<String>() { // from class: io.netty.util.internal.SystemPropertyUtil.1
                    @Override // java.security.PrivilegedAction
                    public String run() {
                        return System.getProperty(str);
                    }
                });
            }
        } catch (Exception e2) {
            if (!loggedException) {
                log("Unable to retrieve a system property '" + str + "'; default values will be used.", e2);
                loggedException = true;
            }
        }
        return str3 == null ? str2 : str3;
    }

    private static void log(String str, Exception exc) {
        if (initializedLogger) {
            logger.warn(str, (Throwable) exc);
        } else {
            Logger.getLogger(SystemPropertyUtil.class.getName()).log(Level.WARNING, str, (Throwable) exc);
        }
    }
}
