org.infinispan.util
Class Util

java.lang.Object
  extended by org.infinispan.util.Util

public final class Util
extends Object

General utility methods used throughout the Infinispan code base.

Since:
4.0
Author:
Brian Stansberry, Galder ZamarreƱo

Nested Class Summary
static class Util.MapModifications
          Static inner class that holds 3 maps - for data added, removed and modified.
 
Method Summary
static void close(Closeable cl)
           
static void flushAndCloseOutput(ObjectOutput o)
           
static void flushAndCloseStream(OutputStream o)
           
static String formatString(Object message, Object... params)
           
static
<T> T
getInstance(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 Object getInstance(String classname)
          Instantiates a class based on the class name provided.
static
<T> T
getInstanceStrict(Class<T> clazz)
          Similar to getInstance(Class) except that exceptions are propagated to the caller.
static Object getInstanceStrict(String classname)
          Similar to getInstance(String) except that exceptions are propagated to the caller.
static Class loadClass(String classname)
          Loads the specified class using this class's classloader, or, if it is null (i.e.
static Class loadClassStrict(String classname)
          Similar to loadClass(String) except that any ClassNotFoundExceptions experienced is propagated to the caller.
static InputStream loadResourceAsStream(String resource)
           
static String padString(String s, int minWidth)
           
static String prettyPrintTime(long millis)
          Prints a time for display
static String prettyPrintTime(long time, TimeUnit unit)
           
static String printArray(byte[] array, boolean withHash)
           
static boolean safeEquals(Object a, Object b)
          Null-safe equality test.
static void safeRelease(Lock toRelease)
          Releases a lock and swallows any IllegalMonitorStateExceptions - so it is safe to call this method even if the lock is not locked, or not locked by the current thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

loadClass

public static Class loadClass(String classname)
Loads the specified class using this class's classloader, or, if it is null (i.e. this class was loaded by the bootstrap classloader), the system 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 is wrapped as a ConfigurationException and is re-thrown.

Parameters:
classname - name of the class to load
Returns:
the class

loadClassStrict

public static Class loadClassStrict(String classname)
                             throws ClassNotFoundException
Similar to loadClass(String) except that any ClassNotFoundExceptions experienced is propagated to the caller.

Parameters:
classname - name of the class to load
Returns:
the class
Throws:
ClassNotFoundException

getInstance

public static <T> T getInstance(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.

Any exceptions encountered are wrapped in a ConfigurationException and rethrown.

Parameters:
clazz - class to instantiate
Returns:
an instance of the class

getInstanceStrict

public static <T> T getInstanceStrict(Class<T> clazz)
                           throws IllegalAccessException,
                                  InstantiationException
Similar to getInstance(Class) except that exceptions are propagated to the caller.

Parameters:
clazz - class to instantiate
Returns:
an instance of the class
Throws:
IllegalAccessException
InstantiationException

getInstance

public static Object getInstance(String classname)
Instantiates a class based on the class name provided. Instatiation is attempted via an appropriate, static factory method named getInstance() first, and failing the existence of an appropriate factory, falls back to an empty constructor.

Any exceptions encountered loading and instantiating the class is wrapped in a ConfigurationException.

Parameters:
classname - class to instantiate
Returns:
an instance of classname

getInstanceStrict

public static Object getInstanceStrict(String classname)
                                throws ClassNotFoundException,
                                       InstantiationException,
                                       IllegalAccessException
Similar to getInstance(String) except that exceptions are propagated to the caller.

Parameters:
classname - class to instantiate
Returns:
an instance of classname
Throws:
ClassNotFoundException
InstantiationException
IllegalAccessException

safeEquals

public static boolean safeEquals(Object a,
                                 Object b)
Null-safe equality test.

Parameters:
a - first object to compare
b - second object to compare
Returns:
true if the objects are equals or both null, false otherwise.

loadResourceAsStream

public static InputStream loadResourceAsStream(String resource)

prettyPrintTime

public static String prettyPrintTime(long time,
                                     TimeUnit unit)

prettyPrintTime

public static String prettyPrintTime(long millis)
Prints a time for display

Parameters:
millis - time in millis
Returns:
the time, represented as millis, seconds, minutes or hours as appropriate, with suffix

close

public static void close(Closeable cl)

flushAndCloseStream

public static void flushAndCloseStream(OutputStream o)

flushAndCloseOutput

public static void flushAndCloseOutput(ObjectOutput o)

formatString

public static String formatString(Object message,
                                  Object... params)

printArray

public static String printArray(byte[] array,
                                boolean withHash)

padString

public static String padString(String s,
                               int minWidth)

safeRelease

public static final void safeRelease(Lock toRelease)
Releases a lock and swallows any IllegalMonitorStateExceptions - so it is safe to call this method even if the lock is not locked, or not locked by the current thread.

Parameters:
toRelease - lock to release

Google Analytics

Copyright © 2010 JBoss, a division of Red Hat. All Rights Reserved.