com.sun.faban.common
Class Utilities

java.lang.Object
  extended by com.sun.faban.common.Utilities

public class Utilities
extends Object

Common utilities, usually accessible via static import.


Field Summary
static String masterFileSeparator
          The file separator on the master.
static String masterPathSeparator
          The path separator on the master.
 
Constructor Summary
Utilities()
           
 
Method Summary
static String convertPath(String path)
          Attempts to convert a path from Windows to Unix.
static String escapeXML(String message)
          Formats the message to be XML compatible, with the XML escaping.
static void escapeXML(String message, StringBuilder msgBuffer)
          Formats the message to be XML compatible, with the XML escaping.
static File getJarFile(Class clazz)
          Obtains the jar file that contains the class in question.
static String getJavaHome()
          Obtains the javaHome of the current JVM.
static boolean isIpv4Address(String name)
          Tests if a given host name is an ipv4 address.
static String parseEscapedString(String s)
          Parses a string escaped with \n, \t, \020, etc.
static List<NameValuePair<Integer>> parseHostPorts(String hostPorts)
          Parses the host:port string and puts the list of host:port pairs into a list.
static String parseHostPorts(String hostPorts, List<NameValuePair<Integer>> hostPortList, Set<String> hostSet)
          Parses the host:port string and puts the list of host:port pairs into the hostPortList.
static int selectBucket(int current, int total, int buckets)
          Simple, but frequently used utility function to determine which bucket or group the current value belongs to, providing the total and the number of buckets the values get divided into.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

masterFileSeparator

public static String masterFileSeparator
The file separator on the master.


masterPathSeparator

public static String masterPathSeparator
The path separator on the master.

Constructor Detail

Utilities

public Utilities()
Method Detail

convertPath

public static String convertPath(String path)
Attempts to convert a path from Windows to Unix. This is needed as '/' separated paths are well accepted by the JVM on windows, but '\' in the path is rejected on all Unix-based JVMs.

Parameters:
path - The path to convert
Returns:
The converted path

parseEscapedString

public static String parseEscapedString(String s)
Parses a string escaped with \n, \t, \020, etc. Returns the properly escaped string.

Parameters:
s - The string with backslashes
Returns:
The string with control characters or unicode

getJavaHome

public static String getJavaHome()
Obtains the javaHome of the current JVM.

Returns:
The current javaHome

getJarFile

public static File getJarFile(Class clazz)
Obtains the jar file that contains the class in question.

Parameters:
clazz - The given class
Returns:
The jar file containing the class, or null if the class is not local or not loaded from a jar file

parseHostPorts

public static List<NameValuePair<Integer>> parseHostPorts(String hostPorts)
Parses the host:port string and puts the list of host:port pairs into a list.

Parameters:
hostPorts - The host:port string
Returns:
list of host and ports

parseHostPorts

public static String parseHostPorts(String hostPorts,
                                    List<NameValuePair<Integer>> hostPortList,
                                    Set<String> hostSet)
Parses the host:port string and puts the list of host:port pairs into the hostPortList.

Parameters:
hostPorts - The host:port string
hostPortList - The list to insert the host:port pairs
hostSet - The set to insert host names, null if not needed
Returns:
list of host names, space separated

selectBucket

public static int selectBucket(int current,
                               int total,
                               int buckets)
Simple, but frequently used utility function to determine which bucket or group the current value belongs to, providing the total and the number of buckets the values get divided into. If there is a remainder in the division, the remainder is spread equally to the lower numbered buckets. Those buckets will be one value larger than the higher numbered buckets.

Parameters:
current - The current value
total - The total count
buckets - The number of buckets to divide the set into.
Returns:
The bucket number of the current value, starting with 0

escapeXML

public static String escapeXML(String message)
Formats the message to be XML compatible, with the XML escaping.

Parameters:
message - The raw message
Returns:
a localized and formatted message

escapeXML

public static void escapeXML(String message,
                             StringBuilder msgBuffer)
Formats the message to be XML compatible, with the XML escaping.

Parameters:
message - The raw message
msgBuffer - The buffer to write the escaped string

isIpv4Address

public static boolean isIpv4Address(String name)
Tests if a given host name is an ipv4 address.

Parameters:
name - The host name
Returns:
true if the name is an ipv4 address, false otherwise