public final class Util
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static byte[] |
EMPTY_BYTE_ARRAY |
static byte[][] |
EMPTY_BYTE_ARRAY_ARRAY |
static java.lang.Object[] |
EMPTY_OBJECT_ARRAY |
static java.lang.String[] |
EMPTY_STRING_ARRAY |
| Modifier and Type | Method and Description |
|---|---|
static void |
addHexByte(java.lang.StringBuilder buf,
byte b) |
static <T> T[] |
arrayConcat(T[] first,
T[]... rest)
Concatenates an arbitrary number of arrays returning a new array containing all elements
|
static <T> java.util.Set<T> |
asSet(T... a) |
static <T> T |
cloneWithMarshaller(Marshaller marshaller,
T x)
Clones parameter x of type T with a given Marshaller reference;
|
static void |
close(java.lang.AutoCloseable... cls) |
static void |
close(java.lang.AutoCloseable cl) |
static void |
close(javax.naming.Context ctx) |
static void |
close(java.net.Socket s) |
static java.lang.Runnable |
composeWithExceptions(java.lang.Runnable a,
java.lang.Runnable b)
Given two Runnables, return a Runnable that executes both in sequence,
even if the first throws an exception, and if both throw exceptions, add
any exceptions thrown by the second as suppressed exceptions of the first.
|
static java.lang.Double |
constructDouble(java.lang.Class<?> type,
java.lang.Object o) |
static long |
currentMillisFromNanotime()
System.nanoTime() is less expensive than System.currentTimeMillis() and better suited
to measure time intervals. |
static int |
findNextHighestPowerOfTwo(int num)
Returns a number such that the number is a power of two that is equal to, or greater than, the number passed in as
an argument.
|
static void |
flushAndCloseOutput(java.io.ObjectOutput o) |
static void |
flushAndCloseStream(java.io.OutputStream o) |
static java.lang.String |
formatString(java.lang.Object message,
java.lang.Object... params) |
static java.lang.ClassLoader[] |
getClassLoaders(java.lang.ClassLoader appClassLoader) |
static <T> T |
getInstance(java.lang.Class<T> clazz)
Instantiates a class by first attempting a static factory method named getInstance() on the class
and then falling back to an empty constructor.
|
static <T> T |
getInstance(java.lang.String classname,
java.lang.ClassLoader cl)
Instantiates a class based on the class name provided.
|
static <T> T |
getInstanceStrict(java.lang.Class<T> clazz)
Similar to
getInstance(Class) except that exceptions are propagated to the caller. |
static <T> T |
getInstanceStrict(java.lang.String classname,
java.lang.ClassLoader cl)
Similar to
getInstance(String, ClassLoader) except that exceptions are propagated to the caller. |
static <T> java.util.function.Supplier<T> |
getInstanceSupplier(java.lang.Class<T> klass) |
static <T> java.util.function.Supplier<T> |
getInstanceSupplier(java.lang.String className,
java.lang.ClassLoader classLoader) |
static int |
getNormalizedHash(java.lang.Object object,
Hash hashFct)
Applies the given hash function to the hash code of a given object, and then normalizes it to ensure a positive
value is always returned.
|
static java.io.InputStream |
getResourceAsStream(java.lang.String resourcePath,
java.lang.ClassLoader userClassLoader) |
static java.lang.String |
getResourceAsString(java.lang.String resourcePath,
java.lang.ClassLoader userClassLoader) |
static int |
getSegmentSize(int numSegments)
Returns the size of each segment, given a number of segments.
|
static int |
hashCode(byte[] bytes,
int size)
A function that calculates hash code of a byte array based on its
contents but using the given size parameter as deliminator for the
content.
|
static java.lang.String |
hexDump(byte[] buffer) |
static java.lang.String |
hexDump(java.nio.ByteBuffer buffer) |
static java.lang.String |
hexIdHashCode(java.lang.Object o)
Prints the identity hash code of the object passed as parameter
in an hexadecimal format in order to safe space.
|
static boolean |
isBasicType(java.lang.Class<?> type) |
static boolean |
isIBMJavaVendor() |
static boolean |
isOSGiContext()
Tries to determine if the code is running in an OSGi context.
|
static java.lang.String |
join(java.util.List<java.lang.String> strings,
java.lang.String separator) |
static <T> java.lang.Class<T> |
loadClass(java.lang.String classname,
java.lang.ClassLoader cl)
Loads the specified class using the passed classloader, or, if it is
null the Infinispan classes'
classloader. |
static <T> java.lang.Class<T> |
loadClassStrict(java.lang.String classname,
java.lang.ClassLoader userClassLoader)
Loads the specified class using the passed classloader, or, if it is
null the Infinispan classes' classloader. |
static <T> T |
newInstanceOrNull(java.lang.Class<T> clazz,
java.lang.Class[] parameterTypes,
java.lang.Object... arguments)
Instantiates a class by invoking the constructor that matches the provided parameter types passing the given
arguments.
|
static java.lang.Object[] |
objectArray(int length) |
static java.lang.String |
padString(java.lang.String s,
int minWidth) |
static java.lang.String |
prettyPrintSubject(javax.security.auth.Subject subject)
Prints
Subject's principals as a one-liner
(as opposed to default Subject's toString() method, which prints every principal on separate line). |
static java.lang.String |
prettyPrintTime(long millis)
Prints a time for display
|
static java.lang.String |
prettyPrintTime(long time,
java.util.concurrent.TimeUnit unit) |
static java.lang.String |
printArray(byte[] array) |
static java.lang.String |
printArray(byte[] array,
boolean withHash) |
static java.lang.String |
read(java.io.InputStream is)
Reads the given InputStream fully, closes the stream and returns the result as a String.
|
static byte[] |
readStream(java.io.InputStream is)
Reads the given InputStream fully, closes the stream and returns the result as a byte array.
|
static void |
recursiveFileRemove(java.io.File directory)
Deletes directory recursively.
|
static void |
recursiveFileRemove(java.lang.String directoryName)
Deletes directory recursively.
|
static void |
renameTempFile(java.io.File tempFile,
java.io.File lockFile,
java.io.File dstFile) |
static CacheException |
rewrapAsCacheException(java.lang.Throwable t) |
static boolean |
safeEquals(java.lang.Object a,
java.lang.Object b)
Null-safe equality test.
|
static java.lang.String[] |
stringArray(int length) |
static java.lang.String |
threadDump() |
static java.util.UUID |
threadLocalRandomUUID()
Uses a
ThreadLocalRandom to generate a UUID. |
static char[] |
toCharArray(java.lang.String s) |
static java.lang.String |
toHexString(byte[] input) |
static java.lang.String |
toHexString(byte[] input,
int limit) |
static java.lang.String |
toHexString(byte[] input,
int offset,
int limit) |
static <E> java.lang.String |
toStr(java.util.Collection<E> collection) |
static java.lang.String |
toStr(java.lang.Object o) |
static java.lang.String |
unicodeEscapeString(java.lang.String s) |
static java.lang.String |
unicodeUnescapeString(java.lang.String s) |
static java.lang.String |
xmlify(java.lang.String s) |
public static final java.lang.Object[] EMPTY_OBJECT_ARRAY
public static final java.lang.String[] EMPTY_STRING_ARRAY
public static final byte[] EMPTY_BYTE_ARRAY
public static final byte[][] EMPTY_BYTE_ARRAY_ARRAY
public static <T> java.lang.Class<T> loadClass(java.lang.String classname,
java.lang.ClassLoader cl)
Loads the specified class using the passed classloader, or, if it is null the Infinispan classes'
classloader.
If loadtime instrumentation via GenerateInstrumentedClassLoader is used, this class may be loaded by the bootstrap classloader.
If the class is not found, the ClassNotFoundException or NoClassDefFoundError is wrapped as a
CacheConfigurationException and is re-thrown.
classname - name of the class to loadcl - the application classloader which should be used to load the class, or null if the class is always packaged with
InfinispanCacheConfigurationException - if the class cannot be loadedpublic static boolean isOSGiContext()
public static java.lang.ClassLoader[] getClassLoaders(java.lang.ClassLoader appClassLoader)
public static <T> java.lang.Class<T> loadClassStrict(java.lang.String classname,
java.lang.ClassLoader userClassLoader)
throws java.lang.ClassNotFoundException
Loads the specified class using the passed classloader, or, if it is null the Infinispan classes' classloader.
If loadtime instrumentation via GenerateInstrumentedClassLoader is used, this class may be loaded by the bootstrap classloader.
classname - name of the class to loaduserClassLoader - the application classloader which should be used to load the class, or null if the class is always packaged with
Infinispanjava.lang.ClassNotFoundException - if the class cannot be loadedpublic static java.io.InputStream getResourceAsStream(java.lang.String resourcePath,
java.lang.ClassLoader userClassLoader)
public static java.lang.String getResourceAsString(java.lang.String resourcePath,
java.lang.ClassLoader userClassLoader)
throws java.io.IOException
java.io.IOExceptionpublic static <T> T newInstanceOrNull(java.lang.Class<T> clazz,
java.lang.Class[] parameterTypes,
java.lang.Object... arguments)
CacheConfigurationException and rethrown.T - the instance typeclazz - class to instantiatepublic static <T> T getInstance(java.lang.Class<T> clazz)
CacheConfigurationException and rethrown.clazz - class to instantiatepublic static <T> T getInstanceStrict(java.lang.Class<T> clazz)
throws java.lang.IllegalAccessException,
java.lang.InstantiationException
getInstance(Class) except that exceptions are propagated to the caller.clazz - class to instantiatejava.lang.IllegalAccessExceptionjava.lang.InstantiationExceptionpublic static <T> T getInstance(java.lang.String classname,
java.lang.ClassLoader cl)
CacheConfigurationException.classname - class to instantiatepublic static <T> T getInstanceStrict(java.lang.String classname,
java.lang.ClassLoader cl)
throws java.lang.ClassNotFoundException,
java.lang.InstantiationException,
java.lang.IllegalAccessException
getInstance(String, ClassLoader) except that exceptions are propagated to the caller.classname - class to instantiatejava.lang.ClassNotFoundExceptionjava.lang.InstantiationExceptionjava.lang.IllegalAccessExceptionpublic static <T> T cloneWithMarshaller(Marshaller marshaller, T x)
public static java.lang.Runnable composeWithExceptions(java.lang.Runnable a,
java.lang.Runnable b)
public static boolean safeEquals(java.lang.Object a,
java.lang.Object b)
a - first object to compareb - second object to comparepublic static java.lang.String prettyPrintTime(long time,
java.util.concurrent.TimeUnit unit)
public static long currentMillisFromNanotime()
System.nanoTime() is less expensive than System.currentTimeMillis() and better suited
to measure time intervals. It's NOT suited to know the current time, for example to be compared
with the time of other nodes.System.nanoTime(), but converted in Milliseconds.public static java.lang.String prettyPrintTime(long millis)
millis - time in millispublic static byte[] readStream(java.io.InputStream is)
throws java.io.IOException
is - the stream to readjava.io.IOException - in case of stream read errorspublic static java.lang.String read(java.io.InputStream is)
throws java.io.IOException
is - the stream to readjava.io.IOException - in case of stream read errorspublic static void close(java.lang.AutoCloseable cl)
public static void close(java.net.Socket s)
public static void close(java.lang.AutoCloseable... cls)
public static void close(javax.naming.Context ctx)
public static void flushAndCloseStream(java.io.OutputStream o)
public static void flushAndCloseOutput(java.io.ObjectOutput o)
public static java.lang.String formatString(java.lang.Object message,
java.lang.Object... params)
public static java.lang.String toStr(java.lang.Object o)
public static <E> java.lang.String toStr(java.util.Collection<E> collection)
public static java.lang.String printArray(byte[] array)
public static java.lang.String printArray(byte[] array,
boolean withHash)
public static java.lang.String toHexString(byte[] input)
public static java.lang.String toHexString(byte[] input,
int limit)
public static java.lang.String toHexString(byte[] input,
int offset,
int limit)
public static java.lang.String padString(java.lang.String s,
int minWidth)
public static java.lang.String threadDump()
public static CacheException rewrapAsCacheException(java.lang.Throwable t)
@SafeVarargs public static <T> java.util.Set<T> asSet(T... a)
public static java.lang.String hexIdHashCode(java.lang.Object o)
public static java.lang.String hexDump(byte[] buffer)
public static java.lang.String hexDump(java.nio.ByteBuffer buffer)
public static void addHexByte(java.lang.StringBuilder buf,
byte b)
public static java.lang.Double constructDouble(java.lang.Class<?> type,
java.lang.Object o)
public static int getNormalizedHash(java.lang.Object object,
Hash hashFct)
object - to hashhashFct - hash function to applypublic static int getSegmentSize(int numSegments)
numSegments - number of segments requiredpublic static boolean isIBMJavaVendor()
public static java.lang.String join(java.util.List<java.lang.String> strings,
java.lang.String separator)
public static int findNextHighestPowerOfTwo(int num)
public static int hashCode(byte[] bytes,
int size)
public static java.lang.String prettyPrintSubject(javax.security.auth.Subject subject)
Subject's principals as a one-liner
(as opposed to default Subject's toString() method, which prints every principal on separate line).@SafeVarargs
public static <T> T[] arrayConcat(T[] first,
T[]... rest)
public static java.util.UUID threadLocalRandomUUID()
ThreadLocalRandom to generate a UUID. Faster, but not securepublic static java.lang.String unicodeEscapeString(java.lang.String s)
public static java.lang.String unicodeUnescapeString(java.lang.String s)
public static <T> java.util.function.Supplier<T> getInstanceSupplier(java.lang.Class<T> klass)
public static <T> java.util.function.Supplier<T> getInstanceSupplier(java.lang.String className,
java.lang.ClassLoader classLoader)
public static void recursiveFileRemove(java.lang.String directoryName)
directoryName - Directory to be deletedpublic static void recursiveFileRemove(java.io.File directory)
directory - Directory to be deletedpublic static boolean isBasicType(java.lang.Class<?> type)
public static java.lang.String xmlify(java.lang.String s)
public static char[] toCharArray(java.lang.String s)
public static java.lang.Object[] objectArray(int length)
public static java.lang.String[] stringArray(int length)
public static void renameTempFile(java.io.File tempFile,
java.io.File lockFile,
java.io.File dstFile)
throws java.io.IOException
java.io.IOException