Util
Date: 2018-05-06

com.mysql.jdbc

## Class Util

- java.lang.Object
- - com.mysql.jdbc.Util

-     public class Util
      extends java.lang.Object

  Various utility methods for the driver.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `(package private) class` | `Util.RandStructcture`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Util()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static java.util.Map<java.lang.Object,java.lang.Object>` | `calculateDifferences(java.util.Map<?,?> map1, java.util.Map<?,?> map2)`
    `static java.lang.Class<?>[]` | `getImplementedInterfaces(java.lang.Class<?> clazz)` Retrieves a list with all interfaces implemented by the given class.
    `static java.lang.Object` | `getInstance(java.lang.String className, java.lang.Class<?>[] argTypes, java.lang.Object[] args, ExceptionInterceptor exceptionInterceptor)`
    `static int` | `getJVMVersion()`
    `static java.lang.Object` | `handleNewInstance(java.lang.reflect.Constructor<?> ctor, java.lang.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
    `static long[]` | `hashPre41Password(java.lang.String password)`
    `static long[]` | `hashPre41Password(java.lang.String password, java.lang.String encoding)`
    `static boolean` | `interfaceExists(java.lang.String hostname)` Does a network interface exist locally with the given hostname?
    `static boolean` | `isColdFusion()`
    `static boolean` | `isCommunityEdition(java.lang.String serverVersion)` Checks whether the given server version string is a MySQL Community edition
    `static boolean` | `isEnterpriseEdition(java.lang.String serverVersion)` Checks whether the given server version string is a MySQL Enterprise edition
    `static boolean` | `isJdbc4()`
    `static boolean` | `isJdbc42()`
    `static boolean` | `isJdbcInterface(java.lang.Class<?> clazz)` Recursively checks for interfaces on the given class to determine if it implements a java.sql, javax.sql or com.mysql.jdbc interface.
    `static boolean` | `isJdbcPackage(java.lang.String packageName)` Check if the package name is a known JDBC package.
    `static java.util.List<Extension>` | `loadExtensions(Connection conn, java.util.Properties props, java.lang.String extensionClassNames, java.lang.String errorMessageKey, ExceptionInterceptor exceptionInterceptor)` Returns initialized instances of classes listed in extensionClassNames.
    `static java.lang.String` | `newCrypt(java.lang.String password, java.lang.String seed, java.lang.String encoding)`
    `(package private) static long[]` | `newHash(byte[] password)`
    `static java.lang.String` | `oldCrypt(java.lang.String password, java.lang.String seed)`
    `(package private) static long` | `oldHash(java.lang.String password)`
    `static java.lang.Object` | `readObject(java.sql.ResultSet resultSet, int index)` Given a ResultSet and an index into the columns of that ResultSet, read binary data from the column which represents a serialized object, and re-create the object.
    `static void` | `resultSetToMap(java.util.Map mappedValues, java.sql.ResultSet rs)`
    `static void` | `resultSetToMap(java.util.Map mappedValues, java.sql.ResultSet rs, int key, int value)`
    `static void` | `resultSetToMap(java.util.Map mappedValues, java.sql.ResultSet rs, java.lang.String key, java.lang.String value)`
    `static java.lang.String` | `scramble(java.lang.String message, java.lang.String password)`
    `static long` | `secondsSinceMillis(long timeInMillis)` Computes the number of seconds elapsed since the given time in milliseconds.
    `static java.lang.String` | `stackTraceToString(java.lang.Throwable ex)` Converts a nested exception into a nicer message
    `static int` | `truncateAndConvertToInt(long longValue)` Converts long to int, truncating to maximum/minimum value if needed.
    `static int[]` | `truncateAndConvertToInt(long[] longArray)` Converts long[] to int[], truncating to maximum/minimum value if needed.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### Util

          public Util()

  - ### Method Detail

    - #### isJdbc4

          public static boolean isJdbc4()

    - #### isJdbc42

          public static boolean isJdbc42()

    - #### getJVMVersion

          public static int getJVMVersion()

    - #### isColdFusion

          public static boolean isColdFusion()

    - #### isCommunityEdition

          public static boolean isCommunityEdition(java.lang.String serverVersion)

      Checks whether the given server version string is a MySQL Community edition

    - #### isEnterpriseEdition

          public static boolean isEnterpriseEdition(java.lang.String serverVersion)

      Checks whether the given server version string is a MySQL Enterprise edition

    - #### newCrypt

          public static java.lang.String newCrypt(java.lang.String password,
                                  java.lang.String seed,
                                  java.lang.String encoding)

    - #### hashPre41Password

          public static long[] hashPre41Password(java.lang.String password,
                                 java.lang.String encoding)

    - #### hashPre41Password

          public static long[] hashPre41Password(java.lang.String password)

    - #### newHash

          static long[] newHash(byte[] password)

    - #### oldCrypt

          public static java.lang.String oldCrypt(java.lang.String password,
                                  java.lang.String seed)

    - #### oldHash

          static long oldHash(java.lang.String password)

    - #### readObject

          public static java.lang.Object readObject(java.sql.ResultSet resultSet,
                                    int index)
                                             throws java.lang.Exception

      Given a ResultSet and an index into the columns of that ResultSet, read binary data from the column which represents a serialized object, and re-create the object.
      Parameters:
        `resultSet` - the ResultSet to use.
        `index` - an index into the ResultSet.
      Returns:
        the object if it can be de-serialized
      Throws:
        `java.lang.Exception` - if an error occurs

    - #### scramble

          public static java.lang.String scramble(java.lang.String message,
                                  java.lang.String password)

      Parameters:
        `message` -
        `password` -

    - #### stackTraceToString

          public static java.lang.String stackTraceToString(java.lang.Throwable ex)

      Converts a nested exception into a nicer message
      Parameters:
        `ex` - the exception to expand into a message.
      Returns:
        a message containing the exception, the message (if any), and a stacktrace.

    - #### getInstance

          public static java.lang.Object getInstance(java.lang.String className,
                                     java.lang.Class<?>[] argTypes,
                                     java.lang.Object[] args,
                                     ExceptionInterceptor exceptionInterceptor)
                                              throws java.sql.SQLException

      Throws:
        `java.sql.SQLException`

    - #### handleNewInstance

          public static final java.lang.Object handleNewInstance(java.lang.reflect.Constructor<?> ctor,
                                           java.lang.Object[] args,
                                           ExceptionInterceptor exceptionInterceptor)
                                                          throws java.sql.SQLException

      Handles constructing new instance with the given constructor and wrapping (or not, as required) the exceptions that could possibly be generated
      Throws:
        `java.sql.SQLException`

    - #### interfaceExists

          public static boolean interfaceExists(java.lang.String hostname)

      Does a network interface exist locally with the given hostname?
      Parameters:
        `hostname` - the hostname (or IP address in string form) to check
      Returns:
        true if it exists, false if no, or unable to determine due to VM version support of java.net.NetworkInterface

    - #### resultSetToMap

          public static void resultSetToMap(java.util.Map mappedValues,
                            java.sql.ResultSet rs)
                                     throws java.sql.SQLException

      Throws:
        `java.sql.SQLException`

    - #### resultSetToMap

          public static void resultSetToMap(java.util.Map mappedValues,
                            java.sql.ResultSet rs,
                            int key,
                            int value)
                                     throws java.sql.SQLException

      Throws:
        `java.sql.SQLException`

    - #### resultSetToMap

          public static void resultSetToMap(java.util.Map mappedValues,
                            java.sql.ResultSet rs,
                            java.lang.String key,
                            java.lang.String value)
                                     throws java.sql.SQLException

      Throws:
        `java.sql.SQLException`

    - #### calculateDifferences

          public static java.util.Map<java.lang.Object,java.lang.Object> calculateDifferences(java.util.Map<?,?> map1,
                                                                              java.util.Map<?,?> map2)

    - #### loadExtensions

          public static java.util.List<Extension> loadExtensions(Connection conn,
                                                 java.util.Properties props,
                                                 java.lang.String extensionClassNames,
                                                 java.lang.String errorMessageKey,
                                                 ExceptionInterceptor exceptionInterceptor)
                                                          throws java.sql.SQLException

      Returns initialized instances of classes listed in extensionClassNames. There is no need to call Extension.init() method after that if you don't change connection or properties.
      Parameters:
        `conn` -
        `props` -
        `extensionClassNames` -
        `errorMessageKey` -
        `exceptionInterceptor` -
      Throws:
        `java.sql.SQLException`

    - #### isJdbcInterface

          public static boolean isJdbcInterface(java.lang.Class<?> clazz)

      Recursively checks for interfaces on the given class to determine if it implements a java.sql, javax.sql or com.mysql.jdbc interface.
      Parameters:
        `clazz` - The class to investigate.

    - #### isJdbcPackage

          public static boolean isJdbcPackage(java.lang.String packageName)

      Check if the package name is a known JDBC package.
      Parameters:
        `packageName` - The package name to check.

    - #### getImplementedInterfaces

          public static java.lang.Class<?>[] getImplementedInterfaces(java.lang.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.
      Parameters:
        `clazz` - The class from which the interface list will be retrieved.
      Returns:
        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.
      Parameters:
        `timeInMillis` - The past instant in milliseconds.
      Returns:
        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.
      Parameters:
        `longValue` -
      Returns:

    - #### truncateAndConvertToInt

          public static int[] truncateAndConvertToInt(long[] longArray)

      Converts long[] to int[], truncating to maximum/minimum value if needed.
      Parameters:
        `longArray` -
      Returns: