|
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.jppf.utils.StringUtils
public final class StringUtils
This class provides a set of utility methods for manipulating strings.
| Field Summary | |
|---|---|
static Charset |
UTF_8
Charset instance for UTF-8 encoding. |
static Object[] |
ZERO_OBJECT
Constant for an empty array of Objects. |
static String[] |
ZERO_STRING
Constant for an empty array of URLs. |
static URL[] |
ZERO_URL
Constant for an empty array of URLs. |
| Method Summary | ||
|---|---|---|
static
|
arrayToString(T[] array)
Get a String representation of an array of any type. |
|
static
|
arrayToString(T[] array,
String sep,
String prefix,
String suffix)
Get a String representation of an array of any type. |
|
static String |
buildString(int[] ports)
Convert an array of int values into a space-separated string. |
|
static String |
buildString(Object... args)
Build a string made of the specified tokens. |
|
static String |
dumpBytes(byte[] bytes,
int start,
int length)
Convert a part of an array of bytes, into a string of space-separated hexadecimal numbers. |
|
static String |
getRemoteHost(Channel channel)
Returns the IP address of the remote host for a socket channel. |
|
static String |
getRemoteHost(SocketAddress address)
Returns the IP address of the remote host for a socket channel. |
|
static String |
getStackTrace(Throwable t)
Get a throwable's stack trace. |
|
static boolean |
isOneOf(String source,
boolean ignoreCase,
String... values)
Determine whether the specified source string is equal to one of the specified values. |
|
static String |
padLeft(String source,
char padChar,
int maxLen)
Format a string so that it fits into a string of specified length. |
|
static String |
padRight(String source,
char padChar,
int maxLen)
Padds a string on the right side with a given character If the string is longer than the specified length, then characters on the right are truncated, ortherwise the specified character is appended to the result on the right to obtain the appropriate length. |
|
static HostPort |
parseHostPort(String s)
Parse a host:port string into a pair made of a host string and an integer port. |
|
static int[] |
parseIntValues(String s)
Parse an array of port numbers from a string containing a list of space-separated port numbers. |
|
static String |
shortenLabel(String key)
Replace pre-determined keywords in a string, with shorter ones. |
|
static boolean |
startsWithOneOf(String source,
boolean ignoreCase,
String... values)
Determine whether the specified source string starts with one of the specified values. |
|
static byte[] |
toBytes(String hexString)
Convert a string of space-separated hexadecimal numbers into an array of bytes. |
|
static String |
toHexString(byte b)
Convert a byte value into a 2-digits hexadecimal value. |
|
static int[] |
toIntArray(InetAddress addr)
Convert an IP address int array. |
|
static int[] |
toIntArray(String source,
Pattern separatorPattern)
Convert a string with separator-separated values into an int array. |
|
static String |
toStringDuration(long elapsed)
Tranform a duration in milliseconds into a string with hours, minutes, seconds and milliseconds.. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final Charset UTF_8
public static final String[] ZERO_STRING
public static final Object[] ZERO_OBJECT
public static final URL[] ZERO_URL
| Method Detail |
|---|
public static String padLeft(String source,
char padChar,
int maxLen)
source - the string to format; if null, it is considered an empty string.padChar - the character used to fill the result up to the specified length.maxLen - the length of the formatted string.
public static String padRight(String source,
char padChar,
int maxLen)
source - the string to pad to the rightpadChar - the character used for paddingmaxLen - the length to pad the string up to
if its length is greater than the padding length
public static String dumpBytes(byte[] bytes,
int start,
int length)
bytes - the array that contains the sequence of byte values to convert.start - the index to start at in the byte array.length - the number of bytes to convert in the array.
public static String toHexString(byte b)
b - the byte value to convert.
public static byte[] toBytes(String hexString)
hexString - the string to convert.
public static String toStringDuration(long elapsed)
elapsed - the duration to transform, expressed in milliseconds.
public static String shortenLabel(String key)
key - the string to shorten.
public static String getRemoteHost(Channel channel)
channel - the channel to get the host from.
public static String getRemoteHost(SocketAddress address)
address - the address to get the host from.
public static <T> String arrayToString(T[] array)
T - the type of the array.array - the array from which to build a string representation.
public static <T> String arrayToString(T[] array,
String sep,
String prefix,
String suffix)
T - the type of the array.array - the array from which to build a string representation.sep - the separator to use for values. If null, no separator is used.prefix - the prefix to use at the start of the resulting string. If null, no prefix is used.suffix - the suffix to use at the end of the resulting string. If null, no suffix is used.
public static int[] parseIntValues(String s)
s - list of space-separated port numbers
public static String buildString(int[] ports)
ports - list of port numbers
public static HostPort parseHostPort(String s)
s - a host:port string.
Pair<String, Integer> instance.public static String getStackTrace(Throwable t)
t - the throwable to get the stack trace from.
public static String buildString(Object... args)
args - the tokens composing the string.
public static boolean startsWithOneOf(String source,
boolean ignoreCase,
String... values)
source - the string to match with the values.ignoreCase - specifies whether case should be ignore in the string matching.values - the values to match the source with.
public static boolean isOneOf(String source,
boolean ignoreCase,
String... values)
source - the string to match with the values.ignoreCase - specifies whether case should be ignore in the string matching.values - the values to match the source with.
public static int[] toIntArray(InetAddress addr)
addr - the source address to convert.
public static int[] toIntArray(String source,
Pattern separatorPattern)
separator-separated values into an int array.
source - the source string to convert.separatorPattern - the values separator, expressed as a regular expression, must comply with the specifications for Pattern.
|
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||