|
Jive Messenger 2.2.2 Javadoc | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jivesoftware.util.StringUtils
public class StringUtils
Utility class to peform common String manipulation algorithms.
Constructor Summary | |
---|---|
StringUtils()
|
Method Summary | |
---|---|
static String |
chopAtWord(String string,
int length)
Intelligently chops a String at a word boundary (whitespace) that occurs at the specified index in the argument or before. |
static String |
dateToMillis(Date date)
Formats a Date as a fifteen character long String made up of the Date's padded millisecond value. |
static String |
decodeBase64(byte[] data)
Decodes a base64 aray of bytes. |
static String |
decodeBase64(String data)
Decodes a base64 String. |
static byte[] |
decodeHex(String hex)
Turns a hex encoded string into a byte array. |
static String |
encodeBase64(byte[] data)
Encodes a byte array into a base64 String. |
static String |
encodeBase64(String data)
Encodes a String as a base64 String. |
static String |
encodeHex(byte[] bytes)
Turns an array of bytes into a String representing each byte as an unsigned hex number. |
static String |
escapeForSQL(String string)
Escapes all necessary characters in the String so that it can be used in SQL |
static String |
escapeForXML(String string)
Escapes all necessary characters in the String so that it can be used in an XML doc. |
static String |
escapeHTMLTags(String in)
This method takes a string which may contain HTML tags (ie, <b>, <table>, etc) and converts the '<'' and '>' characters to their HTML escape sequences. |
static String |
hash(String data)
Hashes a String using the Md5 algorithm and returns the result as a String of hexadecimal numbers. |
static String |
randomString(int length)
Returns a random String of numbers and letters (lower and upper case) of the specified length. |
static String |
replace(String string,
String oldString,
String newString)
Replaces all instances of oldString with newString in string. |
static String |
replace(String line,
String oldString,
String newString,
int[] count)
Replaces all instances of oldString with newString in line. |
static String |
replaceIgnoreCase(String line,
String oldString,
String newString)
Replaces all instances of oldString with newString in line with the added feature that matches of newString in oldString ignore case. |
static String |
replaceIgnoreCase(String line,
String oldString,
String newString,
int[] count)
Replaces all instances of oldString with newString in line with the added feature that matches of newString in oldString ignore case. |
static String |
stripTags(String in)
This method takes a string and strips out all tags except tags while still leaving the tag body intact. |
static String[] |
toLowerCaseWordArray(String text)
Converts a line of text into an array of lower case words using a BreakIterator.wordInstance(). |
static String |
unescapeFromXML(String string)
Unescapes the String by converting XML escape sequences back into normal characters. |
static String |
wordWrap(String input,
int width,
Locale locale)
Reformats a string where lines that are longer than width are split apart at the earliest wordbreak or at maxLength, whichever is sooner. |
static String |
zeroPadString(String string,
int length)
Pads the supplied String with 0's to the specified length and returns the result as a new String. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public StringUtils()
Method Detail |
---|
public static final String replace(String string, String oldString, String newString)
string
- the String to search to perform replacements onoldString
- the String that should be replaced by newStringnewString
- the String that will replace all instances of oldString
public static final String replaceIgnoreCase(String line, String oldString, String newString)
line
- the String to search to perform replacements onoldString
- the String that should be replaced by newStringnewString
- the String that will replace all instances of oldString
public static final String replaceIgnoreCase(String line, String oldString, String newString, int[] count)
line
- the String to search to perform replacements onoldString
- the String that should be replaced by newStringnewString
- the String that will replace all instances of oldStringcount
- a value that will be updated with the number of replaces
performed.
public static final String replace(String line, String oldString, String newString, int[] count)
line
- the String to search to perform replacements onoldString
- the String that should be replaced by newStringnewString
- the String that will replace all instances of oldString
public static final String stripTags(String in)
in
- the text to be converted.
public static final String escapeHTMLTags(String in)
in
- the text to be converted.
public static final String hash(String data)
data
- the String to compute the hash of.
public static final String encodeHex(byte[] bytes)
bytes
- an array of bytes to convert to a hex-string
public static final byte[] decodeHex(String hex)
hex
- a hex encoded String to transform into a byte array.
public static String encodeBase64(String data)
data
- a String to encode.
public static String encodeBase64(byte[] data)
data
- a byte array to encode.
public static String decodeBase64(String data)
data
- a base64 encoded String to decode.
public static String decodeBase64(byte[] data)
data
- a base64 encode byte array to decode.
public static final String[] toLowerCaseWordArray(String text)
This method is under the Jive Open Source Software License and was written by Mark Imbriaco.
text
- a String of text to convert into an array of words
public static final String randomString(int length)
The specified length must be at least one. If not, the method will return null.
length
- the desired length of the random String to return.
public static final String chopAtWord(String string, int length)
length
, the String will be chopped
there. If no newline or whitespace is found in string
up to
the index length
, the String will chopped at length
.
For example, chopAtWord("This is a nice String", 10) will return
"This is a" which is the first word boundary less than or equal to 10
characters into the original String.
string
- the String to chop.length
- the index in string
to start looking for a
whitespace boundary at.
string
whose length is less than or
equal to length
, and that is chopped at whitespace.public static String wordWrap(String input, int width, Locale locale)
input
- the String to reformat.width
- the maximum length of any one line.
public static final String escapeForSQL(String string)
string
- the string to escape.
public static final String escapeForXML(String string)
string
- the string to escape.
public static final String unescapeFromXML(String string)
string
- the string to unescape.
public static final String zeroPadString(String string, int length)
string
- the original String to pad.length
- the desired length of the new padded String.
public static final String dateToMillis(Date date)
|
Jive Messenger 2.2.2 Javadoc | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |