chrriis.common
Class Utils

java.lang.Object
  extended by chrriis.common.Utils

public class Utils
extends Object

Author:
Christopher Deckers

Field Summary
static boolean IS_32_BIT
           
static boolean IS_64_BIT
           
static boolean IS_JAVA_6_OR_GREATER
           
static boolean IS_MAC
           
static boolean IS_WINDOWS
           
static boolean IS_WINDOWS_7_OR_GREATER
           
static boolean IS_WINDOWS_VISTA_OR_GREATER
           
static String LINE_SEPARATOR
           
 
Method Summary
static String arrayDeepToString(Object array)
          Produce the deep string value of an array, whatever the actual class type of the array is.
static String decodeURL(String s)
           
static void deleteAll(File fileOrDir)
          Delete the file, or delete the directtory and all its children recursively.
static String encodeURL(String s)
           
static boolean equals(Object o1, Object o2)
          Test the equality of 2 objects, with a check on nullity.
static String escapeXML(String s)
           
static File getClassPathFile(Class<?> clazz)
           
static File getClassPathFile(String resourcePath)
           
static File getDirectory(Class<?> clazz)
           
static File getDirectory(String resourcePath)
           
static File getJARFile(Class<?> clazz)
           
static File getJARFile(String resourcePath)
           
static File getLocalFile(String path)
           
static String getLocalHostAddress()
          Get a local host address on which client and server sockets can connect to communicate.
static String getLocalHostAddress(int port)
          Get a local host address on which client and server sockets can connect to communicate.
static void printStackTraces()
           
static void printStackTraces(PrintStream printStream)
           
static void printStackTraces(PrintWriter printWriter)
           
static String simplifyPath(String path)
          Simplify a path, where separators are '/', by resolving "." and "..".
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

IS_JAVA_6_OR_GREATER

public static final boolean IS_JAVA_6_OR_GREATER

IS_MAC

public static final boolean IS_MAC

IS_WINDOWS

public static final boolean IS_WINDOWS

IS_32_BIT

public static final boolean IS_32_BIT

IS_64_BIT

public static final boolean IS_64_BIT

IS_WINDOWS_VISTA_OR_GREATER

public static final boolean IS_WINDOWS_VISTA_OR_GREATER

IS_WINDOWS_7_OR_GREATER

public static final boolean IS_WINDOWS_7_OR_GREATER

LINE_SEPARATOR

public static final String LINE_SEPARATOR
Method Detail

decodeURL

public static String decodeURL(String s)

encodeURL

public static String encodeURL(String s)

escapeXML

public static String escapeXML(String s)

getLocalFile

public static File getLocalFile(String path)
Returns:
null or a valid File if the path is a URL or path to a valid local file (that exists).

getClassPathFile

public static File getClassPathFile(String resourcePath)

getClassPathFile

public static File getClassPathFile(Class<?> clazz)

getJARFile

public static File getJARFile(String resourcePath)

getJARFile

public static File getJARFile(Class<?> clazz)

getDirectory

public static File getDirectory(String resourcePath)

getDirectory

public static File getDirectory(Class<?> clazz)

deleteAll

public static void deleteAll(File fileOrDir)
Delete the file, or delete the directtory and all its children recursively.

Parameters:
fileOrDir - a file or a directory to delete.

equals

public static boolean equals(Object o1,
                             Object o2)
Test the equality of 2 objects, with a check on nullity.

Parameters:
o1 - the first object.
o2 - the second object.
Returns:
true if both object are equal, which includes the case where both are null.

arrayDeepToString

public static String arrayDeepToString(Object array)
Produce the deep string value of an array, whatever the actual class type of the array is.

Parameters:
array - the array to get the deep string value of.
Returns:
the deep string value of the array, or null if invalid.

simplifyPath

public static String simplifyPath(String path)
Simplify a path, where separators are '/', by resolving "." and "..".

Returns:
the simplified path.

printStackTraces

public static void printStackTraces()

printStackTraces

public static void printStackTraces(PrintStream printStream)

printStackTraces

public static void printStackTraces(PrintWriter printWriter)

getLocalHostAddress

public static String getLocalHostAddress()
Get a local host address on which client and server sockets can connect to communicate. The result is cached so that only the first call may take some time.

Returns:
the local host address that was found, or null.

getLocalHostAddress

public static String getLocalHostAddress(int port)
Get a local host address on which client and server sockets can connect to communicate.

Parameters:
port - the port on which to test, or 0 for a random test port.
Returns:
the local host address that was found, or null.