org.yajul.util
Class StringUtil

java.lang.Object
  extended by org.yajul.util.StringUtil

public class StringUtil
extends java.lang.Object

Provides commonly used string functions.


User: jdavis
Date: Jul 15, 2003
Time: 12:17:49 PM

Author:
jdavis

Constructor Summary
StringUtil()
           
 
Method Summary
static void appendIfNotEmpty(java.lang.String string, java.lang.StringBuffer buf)
          Appends the string to the string buffer IFF it is not 'empty' (null or zero length).
static java.lang.String defaultToString(java.lang.Object o)
          Prints the class name of the object, followed by '@', followed by the hash code of the object, just like java.lang.Object.toString().
static byte[] getBytes(java.lang.String s, java.lang.String charset)
          Returns the String encoded into an array of bytes using the named charset.
static void hexChars(char[] chars, int inByte, char[] out)
          Converts the byte into a two element array of hex characters.
static java.lang.String hexString(byte[] bytes)
          Returns a string containing the hexadecimal representation of the array of bytes.
static java.lang.String hexString(byte[] bytes, java.lang.String separator)
          Returns a string containing the hexadecimal representation of the array of bytes, separated by an optional string.
static void hexString(java.lang.StringBuffer buf, byte[] bytes, java.lang.String separator, boolean lowerCase)
          Appends the hex representation of the bytes to the string buffer, separated by an optional separator string.
static boolean isEmpty(java.lang.String str)
          Returns true if the string is null or zero length.
static byte parseHexChar(char n)
          Convert a hexadecimal character to a byte.
static byte[] parseHexString(java.lang.String hexString)
          Convert a string of hexadecimal characters to a byte array.
static java.lang.String substringAfter(java.lang.String string, java.lang.String delim)
          Returns the substring after the delimiter string, not including the delimiter string.
static java.lang.String substringBefore(java.lang.String string, java.lang.String delim)
          Returns the substring before the delimiter string, not including the delimiter string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringUtil

public StringUtil()
Method Detail

getBytes

public static byte[] getBytes(java.lang.String s,
                              java.lang.String charset)
Returns the String encoded into an array of bytes using the named charset. This is identical to String.getBytes(charset), except that it will use the default encoding if the charset is not available.

Parameters:
s - the string
charset - the name of a supported charset , or null if the default charset is to be used.
Returns:
The string, encoded in either the default charset or the specified charset.

defaultToString

public static java.lang.String defaultToString(java.lang.Object o)
Prints the class name of the object, followed by '@', followed by the hash code of the object, just like java.lang.Object.toString().

Parameters:
o - The object to print.
Returns:
String - The object's default string representation.

isEmpty

public static boolean isEmpty(java.lang.String str)
Returns true if the string is null or zero length.

Parameters:
str - - The string to test.
Returns:
boolean - True if the string is null or zero length.

hexString

public static java.lang.String hexString(byte[] bytes)
Returns a string containing the hexadecimal representation of the array of bytes.

Parameters:
bytes - The array of bytes to turn into hex.
Returns:
String - The hex string.

hexString

public static java.lang.String hexString(byte[] bytes,
                                         java.lang.String separator)
Returns a string containing the hexadecimal representation of the array of bytes, separated by an optional string.

Parameters:
bytes - The array of bytes to turn into hex.
separator - The separator string. If null or zero length, no separator will be used.
Returns:
String - The hex string.

parseHexString

public static byte[] parseHexString(java.lang.String hexString)
Convert a string of hexadecimal characters to a byte array.

Parameters:
hexString - The hexadecimal string
Returns:
The string of hexadecimal characters as a byte array.

parseHexChar

public static byte parseHexChar(char n)
Convert a hexadecimal character to a byte.

Parameters:
n - The hex character
Returns:
the byte

hexString

public static void hexString(java.lang.StringBuffer buf,
                             byte[] bytes,
                             java.lang.String separator,
                             boolean lowerCase)
Appends the hex representation of the bytes to the string buffer, separated by an optional separator string.

Parameters:
bytes - The bytes to convert to hex.
buf - The buffer to append to.
separator - The separator string. If null or zero length, no separator will be used.
lowerCase - True for lower case hex (e.g. 34f0), false for upper case hex (e.g. 34F0).

hexChars

public static void hexChars(char[] chars,
                            int inByte,
                            char[] out)
Converts the byte into a two element array of hex characters.

Parameters:
chars - The hex character set to use (e.g. HEX_BYTES_LOWER / HEX_BYTES_UPPER).
inByte - The input byte.
out - The output array of characters. Length must be >= 2.

appendIfNotEmpty

public static void appendIfNotEmpty(java.lang.String string,
                                    java.lang.StringBuffer buf)
Appends the string to the string buffer IFF it is not 'empty' (null or zero length).

Parameters:
string - The string to append.
buf - The string buffer.
See Also:
isEmpty(String)

substringBefore

public static java.lang.String substringBefore(java.lang.String string,
                                               java.lang.String delim)
Returns the substring before the delimiter string, not including the delimiter string.

Parameters:
string - The string to look in.
delim - The delimiter string.
Returns:
the substring before the delimiter string, not including the delimiter string.

substringAfter

public static java.lang.String substringAfter(java.lang.String string,
                                              java.lang.String delim)
Returns the substring after the delimiter string, not including the delimiter string.

Parameters:
string - The string to look in.
delim - The delimiter string.
Returns:
the substring after the delimiter string, not including the delimiter string.


Copyright © 2008. All Rights Reserved.