Package com.mysql.cj.util
Class Util
java.lang.Object
com.mysql.cj.util.Util
public class Util
extends java.lang.Object
Various utility methods for the driver.
-
Constructor Summary
Constructors Constructor Description Util()
-
Method Summary
Modifier and Type Method 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 java.lang.Object
getInstance(java.lang.String className, java.lang.Class<?>[] argTypes, java.lang.Object[] args, ExceptionInterceptor exceptionInterceptor, java.lang.String errorMessage)
static int
getJVMUpdateNumber()
static int
getJVMVersion()
static java.lang.String
getPackageName(java.lang.Class<?> clazz)
Returns the package name of the given class.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 generatedstatic boolean
interfaceExists(java.lang.String hostname)
Does a network interface exist locally with the given hostname?static boolean
isCommunityEdition(java.lang.String serverVersion)
Checks whether the given server version string is a MySQL Community editionstatic boolean
isEnterpriseEdition(java.lang.String serverVersion)
Checks whether the given server version string is a MySQL Enterprise editionstatic 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.cj.jdbc interface.static boolean
isJdbcPackage(java.lang.String packageName)
Check if the package name is a known JDBC package.static boolean
isNullOrEmpty(java.util.List<?> list)
static boolean
isRunningOnWindows()
Checks if the JVM is running on Windows Operating System.static boolean
jvmMeetsMinimum(int version, int updateNumber)
static <T> java.util.List<T>
loadClasses(java.lang.String extensionClassNames, java.lang.String errorMessageKey, ExceptionInterceptor exceptionInterceptor)
static int
readBlock(java.io.InputStream i, byte[] b, int length, ExceptionInterceptor exceptionInterceptor)
static int
readBlock(java.io.InputStream i, byte[] b, ExceptionInterceptor exceptionInterceptor)
static int
readFully(java.io.Reader reader, char[] buf, int length)
Reads length bytes from reader into buf.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 messagestatic 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.
-
Constructor Details
-
Util
public Util()
-
-
Method Details
-
getJVMVersion
public static int getJVMVersion() -
jvmMeetsMinimum
public static boolean jvmMeetsMinimum(int version, int updateNumber) -
getJVMUpdateNumber
public static int getJVMUpdateNumber() -
isCommunityEdition
public static boolean isCommunityEdition(java.lang.String serverVersion)Checks whether the given server version string is a MySQL Community edition- Parameters:
serverVersion
- full server version string- Returns:
- true if version does not contain "enterprise", "commercial" or "advanced"
-
isEnterpriseEdition
public static boolean isEnterpriseEdition(java.lang.String serverVersion)Checks whether the given server version string is a MySQL Enterprise edition- Parameters:
serverVersion
- full server version string- Returns:
- true if version contains "enterprise", "commercial" or "advanced"
-
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, java.lang.String errorMessage) -
getInstance
public static java.lang.Object getInstance(java.lang.String className, java.lang.Class<?>[] argTypes, java.lang.Object[] args, ExceptionInterceptor exceptionInterceptor) -
handleNewInstance
public 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- Parameters:
ctor
- constructorargs
- arguments for constructorexceptionInterceptor
- exception interceptor- Returns:
- object
-
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
-
calculateDifferences
public static java.util.Map<java.lang.Object,java.lang.Object> calculateDifferences(java.util.Map<?,?> map1, java.util.Map<?,?> map2) -
loadClasses
public static <T> java.util.List<T> loadClasses(java.lang.String extensionClassNames, java.lang.String errorMessageKey, ExceptionInterceptor exceptionInterceptor) -
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.cj.jdbc interface.- Parameters:
clazz
- The class to investigate.- Returns:
- boolean
-
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.- Returns:
- boolean
-
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
- long value- Returns:
- int value
-
truncateAndConvertToInt
public static int[] truncateAndConvertToInt(long[] longArray)Converts long[] to int[], truncating to maximum/minimum value if needed.- Parameters:
longArray
- log values- Returns:
- int values
-
getPackageName
public static java.lang.String getPackageName(java.lang.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.- Parameters:
clazz
- the Class from which to get the package name- Returns:
- the package name
-
isRunningOnWindows
public static boolean isRunningOnWindows()Checks if the JVM is running on Windows Operating System.- Returns:
true
if currently running on Windows,false
otherwise.
-
readFully
public static int readFully(java.io.Reader reader, char[] buf, int length) throws java.io.IOExceptionReads length bytes from reader into buf. Blocks until enough input is available- Parameters:
reader
-Reader
buf
- char array to read intolength
- number of chars to read- Returns:
- the actual number of chars read
- Throws:
java.io.IOException
- if an error occurs
-
readBlock
public static final int readBlock(java.io.InputStream i, byte[] b, ExceptionInterceptor exceptionInterceptor) -
readBlock
public static final int readBlock(java.io.InputStream i, byte[] b, int length, ExceptionInterceptor exceptionInterceptor) -
isNullOrEmpty
public static boolean isNullOrEmpty(java.util.List<?> list)
-