javax.baja.nre.util
Class TextUtil

java.lang.Object
  extended byjavax.baja.nre.util.TextUtil

public class TextUtil
extends java.lang.Object

Text utilities.


Constructor Summary
TextUtil()
           
 
Method Summary
static java.lang.String bytesToHexString(byte[] bs)
           
static char byteToChar(int b, char unprintable)
          Translate the byte into an ASCII char if it is printable.
static java.lang.String byteToHexString(int b)
           
static java.lang.String byteToString(int b)
           
static java.lang.String capitalize(java.lang.String s)
          Capitalize a string using java bean conventions.
static int charToInt(char c)
          Convert a character to a digit.
static java.lang.String decapitalize(java.lang.String s)
          Decapitalize a string using java bean conventions.
static java.lang.String[] ensureCapacity(java.lang.String[] x, int len)
          Ensure the given string has the specified capacity.
static java.lang.String fromFriendly(java.lang.String s)
          Translate a friendly string back into its programatic name.
static java.lang.String getClassName(java.lang.Class cls)
          Get the simple classname without the package name.
static java.lang.String getClassName(java.lang.String className)
          Get the simple classname without the package name, and if an array type, then strip off the trailing semicolon.
static java.lang.String getPackageName(java.lang.Class cls)
          Get the package name.
static java.lang.String getPackageName(java.lang.String className)
          Get the package name from a fully qualified classname.
static java.lang.String getSpaces(int num)
          Get a string which is a number of spaces.
static java.lang.String getZeros(int num)
          Get a string which is a number of zeros.
static int hexCharToInt(char c)
          Convert the given hex character to a digit.
static int indexOf(java.lang.StringBuffer buffer, java.lang.String pattern)
          Returns the index within the StringBuffer of the first occurrence of the specified substring.
static int indexOf(java.lang.StringBuffer buffer, java.lang.String pattern, int fromIndex)
          Returns the index within the StringBuffer of the first occurrence of the specified substring, starting at the specified index.
static java.lang.String intToHexString(int i)
           
static java.lang.String intToHexString(int i, int len)
           
static boolean isHex(java.lang.String str)
          check if all the characters in a given string are hexidecimal, i.e [0-9], [A-F]
static java.lang.String join(java.lang.String[] v, char delim)
          Join an array into a string, using a given delimiter.
static java.lang.String pad(java.lang.String s, int width)
          Pad to the right.
static java.lang.String padLeft(java.lang.String s, int width)
          Pad the given string with spaces to the left so that it is the given width.
static java.lang.String padRight(java.lang.String s, int width)
          Pad the given string with spaces to the right so that it is the given width.
static java.lang.String padZeros(java.lang.String s, int width)
          Pad the given string with zeros to the left so that it is the given width.
static java.lang.StringBuffer replace(java.lang.StringBuffer text, java.lang.String oldStr, java.lang.String newStr)
          Replace, in the given text buffer, all occurences of the old string with the new string.
static java.lang.String replace(java.lang.String text, java.lang.String oldStr, java.lang.String newStr)
          Replace, in the given text, all occurences of the old string with the new string.
static java.lang.String[] split(java.lang.String str, char delim)
          Parse a string into an array, using a given delimiter.
static java.lang.String[] splitAndTrim(java.lang.String str, char delim)
          Parse a string into an array, using a given delimiter, and trim the whitespace from ends each string.
static byte[] stringToBytes(java.lang.String string)
          Convert the passed in String to a byte array by taking the bottom 8 bits of each character it contains.
static java.lang.String stripMarkup(java.lang.String text)
          Strip all the XML or HTML markup out of a piece of text and return the plain text.
static java.lang.String toFriendly(java.lang.String s)
          Translate a programatic name to a friendly name.
static char toLowerCase(char c)
          Do an ASCII only lower case conversion.
static java.lang.String toLowerCase(java.lang.String s)
          Do an ASCII only lower case conversion.
static char toUpperCase(char c)
          Do an ASCII only upper case conversion.
static java.lang.String toUpperCase(java.lang.String s)
          Do an ASCII only upper case conversion.
static java.lang.String[] trim(java.lang.String[] list)
          Trim all the Strings in the specified array.
static java.lang.String trimLeft(java.lang.String s)
          Trim the whitespace from the beginning of a string.
static java.lang.String trimRight(java.lang.String s)
          Trim the whitespace from the end of a string.
static java.lang.String truncate(java.lang.String str, int max)
          Ensure that the given string is no more than 'max' characters long.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextUtil

public TextUtil()
Method Detail

stringToBytes

public static byte[] stringToBytes(java.lang.String string)
Convert the passed in String to a byte array by taking the bottom 8 bits of each character it contains.

Parameters:
string - the string to be converted
Returns:
a byte array representation

byteToString

public static java.lang.String byteToString(int b)
Returns:
byte to decimal string.

bytesToHexString

public static java.lang.String bytesToHexString(byte[] bs)

byteToHexString

public static java.lang.String byteToHexString(int b)
Returns:
byte to two character hex string.

byteToChar

public static char byteToChar(int b,
                              char unprintable)
Translate the byte into an ASCII char if it is printable. If not return the given unprintable char.


intToHexString

public static java.lang.String intToHexString(int i)
Returns:
int to eight character hex string

intToHexString

public static java.lang.String intToHexString(int i,
                                              int len)
Returns:
int to hex string of given length.

charToInt

public static int charToInt(char c)
Convert a character to a digit. For example the char '3' will return 3.


hexCharToInt

public static int hexCharToInt(char c)
Convert the given hex character to a digit. For instance '0' -> 0, 'A' -> 10, 'f' -> 15.


isHex

public static boolean isHex(java.lang.String str)
check if all the characters in a given string are hexidecimal, i.e [0-9], [A-F]


getSpaces

public static java.lang.String getSpaces(int num)
Get a string which is a number of spaces.


pad

public static java.lang.String pad(java.lang.String s,
                                   int width)
Pad to the right.

See Also:
padRight(String, int)

padRight

public static java.lang.String padRight(java.lang.String s,
                                        int width)
Pad the given string with spaces to the right so that it is the given width. If s.length() is greater than width, s is returned.


padLeft

public static java.lang.String padLeft(java.lang.String s,
                                       int width)
Pad the given string with spaces to the left so that it is the given width. If s.length() is greater than width, s is returned.


truncate

public static java.lang.String truncate(java.lang.String str,
                                        int max)
Ensure that the given string is no more than 'max' characters long.


padZeros

public static java.lang.String padZeros(java.lang.String s,
                                        int width)
Pad the given string with zeros to the left so that it is the given width. If s.length() is greater than width, s is returned.


getZeros

public static java.lang.String getZeros(int num)
Get a string which is a number of zeros.


toUpperCase

public static char toUpperCase(char c)
Do an ASCII only upper case conversion. Case conversion with Locale can result in unexpected side effects.


toLowerCase

public static char toLowerCase(char c)
Do an ASCII only lower case conversion. Case conversion with Locale can result in unexpected side effects.


toUpperCase

public static java.lang.String toUpperCase(java.lang.String s)
Do an ASCII only upper case conversion. Case conversion with Locale can result in unexpected side effects.


toLowerCase

public static java.lang.String toLowerCase(java.lang.String s)
Do an ASCII only lower case conversion. Case conversion with Locale can result in unexpected side effects.


capitalize

public static java.lang.String capitalize(java.lang.String s)
Capitalize a string using java bean conventions. For instance "fooBar" becomes "FooBar", for use such as "getFooBar".


decapitalize

public static java.lang.String decapitalize(java.lang.String s)
Decapitalize a string using java bean conventions. For instance "FooBar" becomes "fooBar".


toFriendly

public static java.lang.String toFriendly(java.lang.String s)
Translate a programatic name to a friendly name. This is done based on standard identifier capitalization. So the string "fooBar" would be translated as "Foo Bar".


fromFriendly

public static java.lang.String fromFriendly(java.lang.String s)
Translate a friendly string back into its programatic name.


getClassName

public static java.lang.String getClassName(java.lang.Class cls)
Get the simple classname without the package name.


getClassName

public static java.lang.String getClassName(java.lang.String className)
Get the simple classname without the package name, and if an array type, then strip off the trailing semicolon.


getPackageName

public static java.lang.String getPackageName(java.lang.Class cls)
Get the package name.


getPackageName

public static java.lang.String getPackageName(java.lang.String className)
Get the package name from a fully qualified classname.

Returns:
null if no package is specified.

stripMarkup

public static java.lang.String stripMarkup(java.lang.String text)
Strip all the XML or HTML markup out of a piece of text and return the plain text.


split

public static java.lang.String[] split(java.lang.String str,
                                       char delim)
Parse a string into an array, using a given delimiter.


splitAndTrim

public static java.lang.String[] splitAndTrim(java.lang.String str,
                                              char delim)
Parse a string into an array, using a given delimiter, and trim the whitespace from ends each string.


ensureCapacity

public static java.lang.String[] ensureCapacity(java.lang.String[] x,
                                                int len)
Ensure the given string has the specified capacity. If so then return x, otherwise return a bigger String array with the existing contents.


trim

public static java.lang.String[] trim(java.lang.String[] list)
Trim all the Strings in the specified array.


join

public static java.lang.String join(java.lang.String[] v,
                                    char delim)
Join an array into a string, using a given delimiter.


trimLeft

public static java.lang.String trimLeft(java.lang.String s)
Trim the whitespace from the beginning of a string.


trimRight

public static java.lang.String trimRight(java.lang.String s)
Trim the whitespace from the end of a string.


replace

public static java.lang.String replace(java.lang.String text,
                                       java.lang.String oldStr,
                                       java.lang.String newStr)
Replace, in the given text, all occurences of the old string with the new string.

Throws:
java.lang.NullPointerException - - if text, oldStr or newStr are null.

replace

public static java.lang.StringBuffer replace(java.lang.StringBuffer text,
                                             java.lang.String oldStr,
                                             java.lang.String newStr)
Replace, in the given text buffer, all occurences of the old string with the new string.

Throws:
java.lang.NullPointerException - - if text, oldStr or newStr are null.

indexOf

public static int indexOf(java.lang.StringBuffer buffer,
                          java.lang.String pattern)
Returns the index within the StringBuffer of the first occurrence of the specified substring.

Returns:
if the string argument occurs as a substring within the StringBuffer, then the index of the first character of the first such substring is returned; If it does not occur as a substring, -1 is returned.
Throws:
java.lang.NullPointerException - - if buffer or str is null.

indexOf

public static int indexOf(java.lang.StringBuffer buffer,
                          java.lang.String pattern,
                          int fromIndex)
Returns the index within the StringBuffer of the first occurrence of the specified substring, starting at the specified index.

There is no restriction on the value of fromIndex. If it is negative, it has the same effect as if it were zero: this entire string may be searched. If it is greater than the length of this string, it has the same effect as if it were equal to the length of this string: -1 is returned.

Returns:
if the string argument occurs as a substring within the StringBuffer at a starting index no smaller than fromIndex, then the index of the first character of the first such substring is returned; If it does not occur as a substring starting at fromIndex or beyond, -1 is returned.
Throws:
java.lang.NullPointerException - - if buffer or str is null.