类 Util
- java.lang.Object
-
- com.mysql.cj.util.Util
-
public class Util extends Object
Various utility methods for the driver.
-
-
构造器概要
构造器 构造器 说明 Util()
-
方法概要
所有方法 静态方法 具体方法 修饰符和类型 方法 说明 static Map<Object,Object>calculateDifferences(Map<?,?> map1, Map<?,?> map2)static Class<?>[]getImplementedInterfaces(Class<?> clazz)Retrieves a list with all interfaces implemented by the given class.static ObjectgetInstance(String className, Class<?>[] argTypes, Object[] args, ExceptionInterceptor exceptionInterceptor)static ObjectgetInstance(String className, Class<?>[] argTypes, Object[] args, ExceptionInterceptor exceptionInterceptor, String errorMessage)static intgetJVMUpdateNumber()static intgetJVMVersion()static StringgetPackageName(Class<?> clazz)Returns the package name of the given class.static ObjecthandleNewInstance(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 generatedstatic booleaninterfaceExists(String hostname)Does a network interface exist locally with the given hostname?static booleanisCommunityEdition(String serverVersion)Checks whether the given server version string is a MySQL Community editionstatic booleanisEnterpriseEdition(String serverVersion)Checks whether the given server version string is a MySQL Enterprise editionstatic booleanisJdbcInterface(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 booleanisJdbcPackage(String packageName)Check if the package name is a known JDBC package.static booleanisRunningOnWindows()Checks if the JVM is running on Windows Operating System.static booleanjvmMeetsMinimum(int version, int updateNumber)static <T> List<T>loadClasses(String extensionClassNames, String errorMessageKey, ExceptionInterceptor exceptionInterceptor)static intreadBlock(InputStream i, byte[] b, int length, ExceptionInterceptor exceptionInterceptor)static intreadBlock(InputStream i, byte[] b, ExceptionInterceptor exceptionInterceptor)static intreadFully(Reader reader, char[] buf, int length)Reads length bytes from reader into buf.static longsecondsSinceMillis(long timeInMillis)Computes the number of seconds elapsed since the given time in milliseconds.static StringstackTraceToString(Throwable ex)Converts a nested exception into a nicer messagestatic inttruncateAndConvertToInt(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.
-
-
-
方法详细资料
-
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.
-
getInstance
public static Object getInstance(String className, Class<?>[] argTypes, Object[] args, ExceptionInterceptor exceptionInterceptor, String errorMessage)
-
getInstance
public static Object getInstance(String className, Class<?>[] argTypes, Object[] args, ExceptionInterceptor exceptionInterceptor)
-
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- constructorargs- arguments for constructorexceptionInterceptor- 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)
-
loadClasses
public static <T> List<T> loadClasses(String extensionClassNames, String errorMessageKey, ExceptionInterceptor exceptionInterceptor)
-
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.- 返回:
trueif currently running on Windows,falseotherwise.
-
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-Readerbuf- char array to read intolength- number of chars to read- 返回:
- the actual number of chars read
- 抛出:
IOException- if an error occurs
-
readBlock
public static final int readBlock(InputStream i, byte[] b, ExceptionInterceptor exceptionInterceptor)
-
readBlock
public static final int readBlock(InputStream i, byte[] b, int length, ExceptionInterceptor exceptionInterceptor)
-
-