org.ow2.bonita.util
Class Misc

java.lang.Object
  extended by org.ow2.bonita.util.Misc

public abstract class Misc
extends java.lang.Object

Author:
Marc Blachon, Guillaume Porcher, Charles Souillard, Miguel Valdes, Pierre Vigneras

Nested Class Summary
static class Misc.NullCheckResult
          Represents null value returned by findNull(Object...).
 
Field Summary
static long DAY
          Number of milleseconds in a given day
static java.lang.String LINE_SEPARATOR
          The line separator as defined by the property line.separator.
static java.util.Random RANDOM
          A RANDOM instance.
static java.io.File TMP_DIR
          The file that represents the temporary directory.
 
Method Summary
static void badStateIfEquals(java.lang.Object a, java.lang.Object b, java.lang.String msg)
          This method throw an IllegalStateException if the given parameters are equals (using Object.equals(Object)
static void badStateIfFalse(boolean valueToCheck, java.lang.String msg)
          This method throw an IllegalStateException if the given parameter is false
static void badStateIfNotNull(java.lang.Object valueToCheck, java.lang.String msg)
          This method throw an IllegalStateException if the given parameter is not null
static void badStateIfNull(java.lang.Object valueToCheck, java.lang.String msg)
          This method throw an IllegalStateException if the given parameter is null
static void badStateIfTrue(boolean valueToCheck, java.lang.String msg)
          This method throw an IllegalStateException if the given parameter is true
static void checkArgsNotNull(int offset, java.lang.Object... params)
          Check that the given parameters are not null.
static void checkArgsNotNull(java.lang.Object... params)
          Check that the given parameters are not null.
static
<T extends java.io.Serializable>
java.lang.Throwable
checkReallySerializable(T object)
          Check that the given object is actually serializable.
static java.lang.Exception close(java.io.Closeable closeable)
          Equivalent to #reflectClose(closeable)
static java.lang.Exception close(java.beans.XMLDecoder decoder)
          Equivalent to {@link #reflectClose(decoder)
static java.lang.Exception close(java.beans.XMLEncoder encoder)
          Equivalent to {@link #reflectClose(encoder)
static java.lang.String componentsToString(java.lang.Object[] args, boolean deepToString)
           Smart toString() implementation of arrays.
static java.io.File createTempFile(java.lang.String prefix, java.lang.String suffix, java.io.File directory)
          Perform java.io.File.createTempFile with retries when it fail (limit of 10 retries) (Use to by-pass bug #6325169 on SUN JDK 1.5 on windows) Sames parameter as java.io.File.createTempFile method
static java.lang.String deepToString(java.lang.Object o)
           
static boolean deleteDir(java.io.File dir)
          Delete a given directory and all its contents (whether they are file or directory) WARNING: this method unconditionally modifies the underlying filesystem by erasing files and directories.
static java.io.Serializable deserialize(byte[] buf)
           
static void dynamicLog(int offset, java.util.logging.Level level, java.lang.String msg)
          Log a message to the logger of the caller at the given offset in the stack trace.
static java.util.Set<java.lang.Class<?>> findAllInterfaces(java.lang.Class<?> type)
           Return the list of Class objects representing all interfaces a given class implements.
static java.util.Set<java.lang.Class<?>> findAllSuperTypes(java.lang.Class<?> type)
           Return the list of Class objects representing all super type a given class implements.
static java.util.Set<java.lang.Class<?>> findAllTypes(java.lang.Class<?> type)
           Return the list of Class objects representing every types a given class implements.
static java.lang.Class<?>[] findConstructorClassArgs(java.lang.Class<?>[] subClasses, java.lang.Class<?> classToTest)
           Return the Class[] array representing the types a constructor take as parameters.
static java.lang.Class<?>[] findMethodClassArgs(java.lang.Class<?>[] subClasses, java.lang.Class<?> classToTest, java.lang.String methodName)
           Return the Class[] array representing the types a given method take as parameters.
static Misc.NullCheckResult findNull(java.lang.Object... params)
          Find null parameters in the given list.
static java.lang.String formatDelay(double delay)
           Equivalent to formatDelay(long).
static java.lang.String formatDelay(long delay)
           Format a delay.
static byte[] generateJar(java.lang.Class<?>... classes)
           
static byte[] generateJar(java.util.Map<java.lang.String,byte[]> resources)
           
static byte[] getAllContentFrom(java.io.File file)
          Equivalent to getAllContentFrom(new FileInputStream(file));
static byte[] getAllContentFrom(org.xml.sax.InputSource source)
          Equivalent to getAllContentFrom(source.getByteStream(source));
static byte[] getAllContentFrom(java.io.InputStream in)
          Return the whole underlying stream content into a single String.
static byte[] getAllContentFrom(java.net.URL url)
          Return the whole underlying stream content into a single String.
static java.lang.StackTraceElement getCaller(int offset)
          Return the StackTraceElement at the given offset from this method invocation.
static
<T> T
getChainOf(java.util.List<T> elements)
          Return a proxy that forward void-method invocations to each object specified in the list elements.
static java.lang.String getCurrentThreadStackTrace()
           
static java.lang.String getGenericFullName(java.lang.Class<?> clazz)
          Return the generic name of a given class.
static long getHumanReadableId()
          Generates a human readable id as a long.
static java.lang.String getHumanReadableId(java.lang.String prefix)
          Generates a human readable id prefixed by the given String.
static
<T> T
getLoggerProxyFor(T target, java.util.logging.Logger logger)
          Return a proxy that log method invocations through the provided logger.
static
<T> T
getMBeanProxy(java.lang.Class<T> mbeanInterface, java.lang.String jmxServiceUrl, java.lang.String jmxObjectName)
          Return a proxy implementing all the interfaces specified that forward method invocations to the specified MBean.
static int getPermissionsSize(java.security.Permissions permissions)
           
static java.lang.String getRandomString(int size)
          Generate a RANDOM String of the given size.
static java.util.Map<java.lang.String,byte[]> getResources(java.lang.Class<?>... classes)
           
static java.util.Map<java.lang.String,byte[]> getResourcesFromZip(byte[] barContent)
           
static java.lang.String getStackTraceFrom(java.lang.Throwable t)
           
static java.util.List<java.lang.String> getStringFrom(Misc.NullCheckResult nullCheckResult, java.lang.String... names)
          Return strings mapped to null values in a given @{link Misc.NullCheckResult.
static java.lang.String getUniqueId(java.lang.String prefix)
          Generate a unique identifier prefixed by the given String.
static java.lang.String identityToString(java.lang.Object o)
           Return an "identity string" for a given object.
static void log(java.util.logging.Level level, java.lang.String msg)
          Log the given message at the given level using caller's Logger.
static
<T> T
lookup(java.lang.String name, java.util.Hashtable<java.lang.String,java.lang.String> environment)
           
static java.lang.String prefixAllLines(java.lang.String message, java.lang.String prefix)
          Return a new string based on the given message string where all lines are prefixed by the given prefix.
static java.lang.String primitiveComponentsToString(java.lang.Object array)
           Smart toString() implementation of an array of primitive types.
static int random(int min, int max)
          Returns a random number between min and max value
static java.lang.Exception reflectClose(java.lang.Object o)
          Invoke the close() method on the given object.
static byte[] serialize(java.io.Serializable object)
           
static
<E extends java.lang.Enum<E>>
E
stringToEnum(java.lang.Class<E> c, java.lang.String s)
           
static void unreachableStatement()
           
static void unreachableStatement(java.lang.String reason)
           
static void warnIfEquals(java.util.logging.Level level, java.lang.Object a, java.lang.Object b)
          This method logs at the given level a "warning" if the given parameter are equals
static void warnIfFalse(java.util.logging.Level level, boolean valueToCheck, java.lang.String variableName)
          This method logs at the given level a "warning" if the given parameter is false
static void warnIfNotEquals(java.util.logging.Level level, java.lang.Object a, java.lang.Object b)
          This method logs at the given level a "warning" if the given parameter are not equals
static void warnIfNotNull(java.util.logging.Level level, java.lang.Object valueToCheck, java.lang.String variableName)
          This method logs at the given level a "warning" if the given parameter is not null
static void warnIfNull(java.util.logging.Level level, java.lang.Object valueToCheck, java.lang.String variableName)
          This method logs at the given level a "warning message" if the given parameter is null
static void warnIfTrue(java.util.logging.Level level, boolean valueToCheck, java.lang.String variableName)
          This method logs at the given level a "warning" if the given parameter is true
static void write(java.io.File file, byte[] fileContent)
           
static void write(java.lang.String s, java.io.File f)
          Write the given String to the given file using the default encoding.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RANDOM

public static final java.util.Random RANDOM
A RANDOM instance. Prevent creation of many instances.


LINE_SEPARATOR

public static final java.lang.String LINE_SEPARATOR
The line separator as defined by the property line.separator.


TMP_DIR

public static final java.io.File TMP_DIR
The file that represents the temporary directory. Usually, it is /tmp on Unix platform and C:/TMP on MS Windows.


DAY

public static final long DAY
Number of milleseconds in a given day

See Also:
Constant Field Values
Method Detail

getUniqueId

public static java.lang.String getUniqueId(java.lang.String prefix)
Generate a unique identifier prefixed by the given String.

Parameters:
prefix - the prefix String
Returns:
an UUID String prefixed by prefix
See Also:
UUID

getHumanReadableId

public static java.lang.String getHumanReadableId(java.lang.String prefix)
Generates a human readable id prefixed by the given String. The generated identifier is unique only for the duration of the existence of this class.

Parameters:
prefix - the string prefiy
Returns:
a human readable id prefixed by prefix.

getHumanReadableId

public static long getHumanReadableId()
Generates a human readable id as a long. The generated identifier is unique only for the duration of the existence of this class.

Returns:
a unique id as a long.

random

public static int random(int min,
                         int max)
Returns a random number between min and max value

Parameters:
min - a positive integer
max - a positive integer
Returns:
a random number between min and max value
Throws:
java.lang.IllegalArgumentException - if min >= max

getRandomString

public static java.lang.String getRandomString(int size)
Generate a RANDOM String of the given size.

Parameters:
size - the size of the generated string
Returns:
the RANDOM String

formatDelay

public static final java.lang.String formatDelay(long delay)

Format a delay.

This method returns a human readable string for delay such as the one used in benchmarks. This method is thread safe.

Parameters:
delay - a long value
Returns:
a String value

formatDelay

public static final java.lang.String formatDelay(double delay)

Equivalent to formatDelay(long).

Parameters:
delay - a double value
Returns:
a String value

findAllTypes

public static java.util.Set<java.lang.Class<?>> findAllTypes(java.lang.Class<?> type)

Return the list of Class objects representing every types a given class implements.

Parameters:
type - a Class value
Returns:
a Set value

getGenericFullName

public static java.lang.String getGenericFullName(java.lang.Class<?> clazz)
Return the generic name of a given class. For example, given java.util.Map.class, it returns string java.util.Map

Parameters:
clazz - the class
Returns:
the generic name of a given class.

findAllSuperTypes

public static java.util.Set<java.lang.Class<?>> findAllSuperTypes(java.lang.Class<?> type)

Return the list of Class objects representing all super type a given class implements.

Parameters:
type - a Class value
Returns:
a Set value

findAllInterfaces

public static java.util.Set<java.lang.Class<?>> findAllInterfaces(java.lang.Class<?> type)

Return the list of Class objects representing all interfaces a given class implements.

Parameters:
type - a Class value
Returns:
a List value

findMethodClassArgs

public static java.lang.Class<?>[] findMethodClassArgs(java.lang.Class<?>[] subClasses,
                                                       java.lang.Class<?> classToTest,
                                                       java.lang.String methodName)
                                                throws java.lang.NoSuchMethodException

Return the Class[] array representing the types a given method take as parameters.

Parameters:
subClasses - the classes which are to be subclasses of parameters
classToTest - the class which declares the given method
methodName - the method name
Returns:
the formal parameters class array
Throws:
java.lang.NoSuchMethodException - if a method cannot be found.

findConstructorClassArgs

public static java.lang.Class<?>[] findConstructorClassArgs(java.lang.Class<?>[] subClasses,
                                                            java.lang.Class<?> classToTest)
                                                     throws java.lang.NoSuchMethodException

Return the Class[] array representing the types a constructor take as parameters.

Parameters:
subClasses - the classes which are to be subclasses of parameters
classToTest - the class which declares the constructor
Returns:
the formal parameters class array
Throws:
java.lang.NoSuchMethodException - if a constructor cannot be found

identityToString

public static java.lang.String identityToString(java.lang.Object o)

Return an "identity string" for a given object.

The string returned is:

Parameters:
o - the object to return the identity string of
Returns:
the identity string as defined above

componentsToString

public static java.lang.String componentsToString(java.lang.Object[] args,
                                                  boolean deepToString)

Smart toString() implementation of arrays.

Parameters:
args - the array to return a smart string of.
Returns:
the smart string of the given array.

primitiveComponentsToString

public static java.lang.String primitiveComponentsToString(java.lang.Object array)

Smart toString() implementation of an array of primitive types.

Parameters:
array - the array to return a smart string of.
Returns:
the smart string of the given array.

getAllContentFrom

public static byte[] getAllContentFrom(java.io.File file)
                                throws java.io.IOException
Equivalent to getAllContentFrom(new FileInputStream(file));

Parameters:
file - the file to read
Returns:
the whole content of the file in a single String.
Throws:
java.io.IOException - If an I/O exception occured

getAllContentFrom

public static byte[] getAllContentFrom(org.xml.sax.InputSource source)
                                throws java.io.IOException
Equivalent to getAllContentFrom(source.getByteStream(source));

Parameters:
file - the file to read
Returns:
the whole content of the file in a single String.
Throws:
java.io.IOException - If an I/O exception occured

getAllContentFrom

public static byte[] getAllContentFrom(java.net.URL url)
                                throws java.io.IOException
Return the whole underlying stream content into a single String. Warning: the whole content of stream will be kept in memory!! Use with care!

Parameters:
in - the stream to read
Returns:
the whole content of the stream in a single String.
Throws:
java.io.IOException - if an I/O exception occured

getAllContentFrom

public static byte[] getAllContentFrom(java.io.InputStream in)
                                throws java.io.IOException
Return the whole underlying stream content into a single String. Warning: the whole content of stream will be kept in memory!! Use with care!

Parameters:
in - the stream to read
Returns:
the whole content of the stream in a single String.
Throws:
java.io.IOException - if an I/O exception occured

close

public static java.lang.Exception close(java.io.Closeable closeable)
Equivalent to #reflectClose(closeable)


close

public static java.lang.Exception close(java.beans.XMLEncoder encoder)
Equivalent to {@link #reflectClose(encoder)


close

public static java.lang.Exception close(java.beans.XMLDecoder decoder)
Equivalent to {@link #reflectClose(decoder)


reflectClose

public static java.lang.Exception reflectClose(java.lang.Object o)
Invoke the close() method on the given object. This method uses the reflection API to find a close() method with no arguments. Any exception thrown (including NoSuchMethodException) will be both logged using LOG and returned. If the parameter is null, nothing is done and null is returned.

Parameters:
o - the object to call the close() method on.
Returns:
the exception thrown if any, null otherwise.

getPermissionsSize

public static int getPermissionsSize(java.security.Permissions permissions)
Parameters:
permissions -
Returns:

getMBeanProxy

public static <T> T getMBeanProxy(java.lang.Class<T> mbeanInterface,
                                  java.lang.String jmxServiceUrl,
                                  java.lang.String jmxObjectName)
                       throws java.io.IOException,
                              javax.management.MalformedObjectNameException,
                              javax.management.InstanceNotFoundException,
                              javax.management.MBeanException,
                              javax.management.ReflectionException
Return a proxy implementing all the interfaces specified that forward method invocations to the specified MBean.

Type Parameters:
T -
Parameters:
mbeanInterface - the interface the proxy should implement (the MBean should obviously also implement that interface).
jmxServiceUrl - the JMX service URL
jmxObjectName - the name the MBean has been registered to
Returns:
a proxy implementing the specified interface and that forward method invocations to the specified MBean.
Throws:
java.io.IOException - for any IO problem
javax.management.MalformedObjectNameException - for any JMX Naming problem
javax.management.MBeanException - for any MBean problem
javax.management.ReflectionException - for any problem related to reflection
javax.management.InstanceNotFoundException

getChainOf

public static <T> T getChainOf(java.util.List<T> elements)
Return a proxy that forward void-method invocations to each object specified in the list elements. The invocation order follows the given list order.

Type Parameters:
T - the interface type of the returned proxy and of each elements.
Parameters:
elements - the elements to forward method invocations to
Returns:
the forwarding chaining proxy
See Also:
Chainer, InvocationHandler, Proxy

getLoggerProxyFor

public static <T> T getLoggerProxyFor(T target,
                                      java.util.logging.Logger logger)
Return a proxy that log method invocations through the provided logger.

Type Parameters:
T - the target object type
Parameters:
target - the target object method invocations should be forwarded to
logger - the logger to use for logging
Returns:
a proxy that log method invocations through the provided logger.
See Also:
LoggingInvocationHandler, InvocationHandler, Proxy

findNull

public static Misc.NullCheckResult findNull(java.lang.Object... params)
Find null parameters in the given list. This method returns a Misc.NullCheckResult.

Parameters:
params - the parameters to check
Returns:
a Misc.NullCheckResult representing null parameters.
See Also:
Misc.NullCheckResult

checkArgsNotNull

public static void checkArgsNotNull(java.lang.Object... params)
Check that the given parameters are not null. This method should only be used to check that some parameters given to a given method are not null. The exception message tries its best to produce a helpful message by scanning the stack trace.

Parameters:
params - the parameters to check
Throws:
an - IllegalArgumentException if at least one of the parameters is null

checkArgsNotNull

public static void checkArgsNotNull(int offset,
                                    java.lang.Object... params)
Check that the given parameters are not null. This method should only be used to check that some parameters given to a given method are not null. The exception message tries its best to produce a helpful message by scanning the stack trace.

Parameters:
offset - the offset to use in the stack trace to produce error message
params - the parameters to check
Throws:
an - IllegalArgumentException if at least one of the parameters is null

getCaller

public static java.lang.StackTraceElement getCaller(int offset)
Return the StackTraceElement at the given offset from this method invocation.

Parameters:
offset -
Returns:
a StackTraceElement

getStringFrom

public static java.util.List<java.lang.String> getStringFrom(Misc.NullCheckResult nullCheckResult,
                                                             java.lang.String... names)
Return strings mapped to null values in a given @{link Misc.NullCheckResult. . If the returned @{link List} of String is called l then, it verifies: l.contains(names[i]) if and only if nullCheckResult.isNull(i) returns true. Note that the number of String names given should be of the same size that the one used to get the given Misc.NullCheckResult using findNull(Object...). An IllegalArgumentException is thrown otherwise.

Parameters:
nullCheckResult - the result as returned by findNull(Object...)
names - the strings that should be mapped to null values
Returns:
a List of string mapped to the given Misc.NullCheckResult.
Throws:
java.lang.IllegalArgumentException - if the number of given names is different that NullCheckResult#size()
See Also:
findNull(Object...), Misc.NullCheckResult

badStateIfNull

public static void badStateIfNull(java.lang.Object valueToCheck,
                                  java.lang.String msg)
This method throw an IllegalStateException if the given parameter is null

Parameters:
valueToCheck - the value to check
msg - the message for the thrown exception
See Also:
IllegalStateException

badStateIfNotNull

public static void badStateIfNotNull(java.lang.Object valueToCheck,
                                     java.lang.String msg)
This method throw an IllegalStateException if the given parameter is not null

Parameters:
valueToCheck - the value to check
msg - the message for the thrown exception
See Also:
IllegalStateException

badStateIfTrue

public static void badStateIfTrue(boolean valueToCheck,
                                  java.lang.String msg)
This method throw an IllegalStateException if the given parameter is true

Parameters:
valueToCheck - the value to check
msg - the message for the thrown exception
See Also:
IllegalStateException

badStateIfFalse

public static void badStateIfFalse(boolean valueToCheck,
                                   java.lang.String msg)
This method throw an IllegalStateException if the given parameter is false

Parameters:
valueToCheck - the value to check
msg - the message for the thrown exception
See Also:
IllegalStateException

badStateIfEquals

public static void badStateIfEquals(java.lang.Object a,
                                    java.lang.Object b,
                                    java.lang.String msg)
This method throw an IllegalStateException if the given parameters are equals (using Object.equals(Object)

Parameters:
a - the first object
b - the second object
msg - the message for the thrown exception
See Also:
IllegalStateException

dynamicLog

public static void dynamicLog(int offset,
                              java.util.logging.Level level,
                              java.lang.String msg)
Log a message to the logger of the caller at the given offset in the stack trace. If A.f() calls B.g() that finally calls dynamicLog(1, msg) then, the msg will be logged with a code similar to:
getLogger(B.getClass().getName()).log(level, msg);
If the call was dynamicLog(2, msg) then, the code would be:
getLogger(A.getClass().getName()).log(level, msg);

Parameters:
offset - the offset in the stack trace
level - the level to log the message to
msg - the message to log

log

public static void log(java.util.logging.Level level,
                       java.lang.String msg)
Log the given message at the given level using caller's Logger.

Parameters:
level - a level
msg - the message
See Also:
dynamicLog(int, Level, String)

warnIfNull

public static void warnIfNull(java.util.logging.Level level,
                              java.lang.Object valueToCheck,
                              java.lang.String variableName)
This method logs at the given level a "warning message" if the given parameter is null

Parameters:
level - a log level
valueToCheck - the value to check
variableName - the variable name holding valueToCheck. Can be null.

warnIfNotNull

public static void warnIfNotNull(java.util.logging.Level level,
                                 java.lang.Object valueToCheck,
                                 java.lang.String variableName)
This method logs at the given level a "warning" if the given parameter is not null

Parameters:
level - a log level
valueToCheck - the value to check
variableName - the variable name holding valueToCheck. Can be null.

warnIfTrue

public static void warnIfTrue(java.util.logging.Level level,
                              boolean valueToCheck,
                              java.lang.String variableName)
This method logs at the given level a "warning" if the given parameter is true

Parameters:
level - a log level
valueToCheck - the value to check
variableName - the variable name holding valueToCheck. Can be null.

warnIfFalse

public static void warnIfFalse(java.util.logging.Level level,
                               boolean valueToCheck,
                               java.lang.String variableName)
This method logs at the given level a "warning" if the given parameter is false

Parameters:
level - a log level
valueToCheck - the value to check
variableName - the variable name holding valueToCheck. Can be null.

warnIfEquals

public static void warnIfEquals(java.util.logging.Level level,
                                java.lang.Object a,
                                java.lang.Object b)
This method logs at the given level a "warning" if the given parameter are equals

Parameters:
level - a log level
a - an object
b - another object

warnIfNotEquals

public static void warnIfNotEquals(java.util.logging.Level level,
                                   java.lang.Object a,
                                   java.lang.Object b)
This method logs at the given level a "warning" if the given parameter are not equals

Parameters:
level - a log level
a - an object
b - another object

getCurrentThreadStackTrace

public static java.lang.String getCurrentThreadStackTrace()

getStackTraceFrom

public static java.lang.String getStackTraceFrom(java.lang.Throwable t)

deepToString

public static java.lang.String deepToString(java.lang.Object o)

deleteDir

public static boolean deleteDir(java.io.File dir)
Delete a given directory and all its contents (whether they are file or directory) WARNING: this method unconditionally modifies the underlying filesystem by erasing files and directories. Use with care!

Parameters:
dir - the directory to delete

unreachableStatement

public static void unreachableStatement()

unreachableStatement

public static void unreachableStatement(java.lang.String reason)

stringToEnum

public static <E extends java.lang.Enum<E>> E stringToEnum(java.lang.Class<E> c,
                                                           java.lang.String s)

serialize

public static byte[] serialize(java.io.Serializable object)
                        throws java.io.IOException,
                               java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException

deserialize

public static java.io.Serializable deserialize(byte[] buf)
                                        throws java.io.IOException,
                                               java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException

checkReallySerializable

public static <T extends java.io.Serializable> java.lang.Throwable checkReallySerializable(T object)
Check that the given object is actually serializable. Implementation tries to serialize and deserialize the given object (in memory). Note that null is returned when the given object is serializable. It returns the throwable thrown by either the serialization or the deserialization process. This means, that the object is not really serializable. Therefore the pattern for checking should be written like:
final Throwable error = checkReallySerializable(myObject); if (error == null) { // success } else { // failure, do something with error... error.printStackTrace(); }

Type Parameters:
T - A type (usually extending Serializable
Parameters:
object - the object to check
Returns:
null on success, the exception thrown on error

write

public static void write(java.lang.String s,
                         java.io.File f)
                  throws java.io.IOException
Write the given String to the given file using the default encoding.

Parameters:
s - the string to be written
f - the file to write the given string to
Throws:
java.io.IOException - if an IO error is encoutered (file not found, read-only file, and so on).

write

public static void write(java.io.File file,
                         byte[] fileContent)
                  throws java.io.IOException
Throws:
java.io.IOException

createTempFile

public static java.io.File createTempFile(java.lang.String prefix,
                                          java.lang.String suffix,
                                          java.io.File directory)
                                   throws java.io.IOException
Perform java.io.File.createTempFile with retries when it fail (limit of 10 retries) (Use to by-pass bug #6325169 on SUN JDK 1.5 on windows) Sames parameter as java.io.File.createTempFile method

Parameters:
prefix - Prefix of the file
suffix - Suffix of the file
directory - Target directory
Returns:
An abstract pathname denoting a newly-created empty file
Throws:
java.io.IOException - If a file could not be created

generateJar

public static byte[] generateJar(java.lang.Class<?>... classes)
                          throws java.io.IOException
Throws:
java.io.IOException

getResources

public static java.util.Map<java.lang.String,byte[]> getResources(java.lang.Class<?>... classes)
                                                           throws java.io.IOException
Throws:
java.io.IOException

generateJar

public static byte[] generateJar(java.util.Map<java.lang.String,byte[]> resources)
                          throws java.io.IOException
Throws:
java.io.IOException

getResourcesFromZip

public static java.util.Map<java.lang.String,byte[]> getResourcesFromZip(byte[] barContent)
                                                                  throws java.io.IOException
Throws:
java.io.IOException

lookup

public static <T> T lookup(java.lang.String name,
                           java.util.Hashtable<java.lang.String,java.lang.String> environment)
                throws javax.naming.NamingException
Throws:
javax.naming.NamingException

prefixAllLines

public static java.lang.String prefixAllLines(java.lang.String message,
                                              java.lang.String prefix)
Return a new string based on the given message string where all lines are prefixed by the given prefix.

Parameters:
message - the message to transform
prefix - the prefix to use
Returns:
the prefixed string


Copyright © 2009 OW2 Consortium. All Rights Reserved.