类 Util


  • public class Util
    extends Object
    Various utility methods for the driver.
    • 构造器详细资料

      • Util

        public Util()
    • 方法详细资料

      • getJVMVersion

        public static int getJVMVersion()
      • jvmMeetsMinimum

        public static boolean jvmMeetsMinimum​(int version,
                                              int updateNumber)
      • getJVMUpdateNumber

        public static int getJVMUpdateNumber()
      • isCommunityEdition

        public static boolean isCommunityEdition​(String serverVersion)
        Checks whether the given server version string is a MySQL Community edition
        参数:
        serverVersion - full server version string
        返回:
        true if version does not contain "enterprise", "commercial" or "advanced"
      • isEnterpriseEdition

        public static boolean isEnterpriseEdition​(String serverVersion)
        Checks whether the given server version string is a MySQL Enterprise edition
        参数:
        serverVersion - full server version string
        返回:
        true if version contains "enterprise", "commercial" or "advanced"
      • stackTraceToString

        public static String stackTraceToString​(Throwable ex)
        Converts a nested exception into a nicer message
        参数:
        ex - the exception to expand into a message.
        返回:
        a message containing the exception, the message (if any), and a stacktrace.
      • handleNewInstance

        public static Object handleNewInstance​(Constructor<?> ctor,
                                               Object[] args,
                                               ExceptionInterceptor exceptionInterceptor)
        Handles constructing new instance with the given constructor and wrapping (or not, as required) the exceptions that could possibly be generated
        参数:
        ctor - constructor
        args - arguments for constructor
        exceptionInterceptor - exception interceptor
        返回:
        object
      • interfaceExists

        public static boolean interfaceExists​(String hostname)
        Does a network interface exist locally with the given hostname?
        参数:
        hostname - the hostname (or IP address in string form) to check
        返回:
        true if it exists, false if no, or unable to determine due to VM version support of java.net.NetworkInterface
      • calculateDifferences

        public static Map<Object,​Object> calculateDifferences​(Map<?,​?> map1,
                                                                    Map<?,​?> map2)
      • isJdbcInterface

        public static boolean isJdbcInterface​(Class<?> clazz)
        Recursively checks for interfaces on the given class to determine if it implements a java.sql, javax.sql or com.mysql.cj.jdbc interface.
        参数:
        clazz - The class to investigate.
        返回:
        boolean
      • isJdbcPackage

        public static boolean isJdbcPackage​(String packageName)
        Check if the package name is a known JDBC package.
        参数:
        packageName - The package name to check.
        返回:
        boolean
      • getImplementedInterfaces

        public static Class<?>[] getImplementedInterfaces​(Class<?> clazz)
        Retrieves a list with all interfaces implemented by the given class. If possible gets this information from a cache instead of navigating through the object hierarchy. Results are stored in a cache for future reference.
        参数:
        clazz - The class from which the interface list will be retrieved.
        返回:
        An array with all the interfaces for the given class.
      • secondsSinceMillis

        public static long secondsSinceMillis​(long timeInMillis)
        Computes the number of seconds elapsed since the given time in milliseconds.
        参数:
        timeInMillis - The past instant in milliseconds.
        返回:
        The number of seconds, truncated, elapsed since timeInMillis.
      • truncateAndConvertToInt

        public static int truncateAndConvertToInt​(long longValue)
        Converts long to int, truncating to maximum/minimum value if needed.
        参数:
        longValue - long value
        返回:
        int value
      • truncateAndConvertToInt

        public static int[] truncateAndConvertToInt​(long[] longArray)
        Converts long[] to int[], truncating to maximum/minimum value if needed.
        参数:
        longArray - log values
        返回:
        int values
      • getPackageName

        public static String getPackageName​(Class<?> clazz)
        Returns the package name of the given class. Using clazz.getPackage().getName() is not an alternative because under some class loaders the method getPackage() just returns null.
        参数:
        clazz - the Class from which to get the package name
        返回:
        the package name
      • isRunningOnWindows

        public static boolean isRunningOnWindows()
        Checks if the JVM is running on Windows Operating System.
        返回:
        true if currently running on Windows, false otherwise.
      • readFully

        public static int readFully​(Reader reader,
                                    char[] buf,
                                    int length)
                             throws IOException
        Reads length bytes from reader into buf. Blocks until enough input is available
        参数:
        reader - Reader
        buf - char array to read into
        length - number of chars to read
        返回:
        the actual number of chars read
        抛出:
        IOException - if an error occurs