public class StringUtils
extends java.lang.Object
Constructor and Description |
---|
StringUtils() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
chopAtWord(java.lang.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 java.lang.String |
chopAtWord(java.lang.String string,
int length,
int minLength)
Intelligently chops a String at a word boundary (whitespace) that occurs
at the specified index in the argument or before.
|
static java.lang.String |
chopAtWordsAround(java.lang.String input,
java.lang.String[] wordList,
int numChars)
Returns a substring of the given string which represents the words around
the given word.
|
static int |
countNumberOfOccurences(java.lang.String string,
char c)
Counts the Number of Occurences of a specified char c in string
|
static byte[] |
createChecksum(java.lang.String filename)
creates an MD5 checksum of a File, given the Filepath
|
static java.lang.String |
dateToMillis(java.util.Date date)
Formats a Date as a String.
|
static java.lang.String |
decodeBase64(byte[] data)
Decodes a base64 aray of bytes.
|
static java.lang.String |
decodeBase64(java.lang.String data)
Decodes a base64 String.
|
static byte[] |
decodeHex(java.lang.String hex)
Turns a hex encoded string into a byte array.
|
static java.lang.String |
encodeBase64(byte[] data)
Encodes a byte array into a base64 String.
|
static java.lang.String |
encodeBase64(java.lang.String data)
Encodes a String as a base64 String.
|
static java.lang.String |
encodeHex(byte[] bytes)
Turns an array of bytes into a String representing each byte as an
unsigned hex number.
|
static java.lang.String |
escapeForXML(java.lang.String string)
Escapes all necessary characters in the String so that it can be used
in an XML doc.
|
static java.lang.String |
escapeHTMLTags(java.lang.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 java.lang.String |
getKeyText(int keyCode) |
static java.lang.String |
getMD5Checksum(java.lang.String filepath)
Creates an MD5 Checksum of a File, given the Filepath
|
static java.lang.String |
hash(byte[] data) |
static java.lang.String |
hash(java.lang.String data)
Hashes a String using the Md5 algorithm and returns the result as
a String of hexadecimal numbers.
|
static java.lang.String |
highlightWords(java.lang.String string,
java.lang.String[] words,
java.lang.String startHighlight,
java.lang.String endHighlight)
Highlights words in a string.
|
static boolean |
isValidEmailAddress(java.lang.String addr)
Validate an email address.
|
static java.lang.String |
keyStroke2String(javax.swing.KeyStroke key) |
static java.lang.String |
makeFirstWordCaptial(java.lang.String word)
Converts the first Character of a String to its Uppercase Instance
test -> Test |
static java.lang.String |
modifyWildcards(java.lang.String resource)
Modifies Wildcards such as %random%,%system%,
%version%,%time% into what they represent
|
static java.lang.String |
randomString(int length)
Returns a random String of numbers and letters (lower and upper case) of
the specified length.
|
static java.lang.String |
replace(java.lang.String string,
java.lang.String oldString,
java.lang.String newString)
Replaces all instances of oldString with newString in string.
|
static java.lang.String |
replace(java.lang.String line,
java.lang.String oldString,
java.lang.String newString,
int[] count)
Replaces all instances of oldString with newString in line.
|
static java.lang.String |
replaceIgnoreCase(java.lang.String line,
java.lang.String oldString,
java.lang.String newString)
Replaces all instances of oldString with newString in line with the added
feature that matches of newString in oldString ignore case.
|
static java.lang.String |
replaceIgnoreCase(java.lang.String line,
java.lang.String oldString,
java.lang.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 java.lang.String |
stripTags(java.lang.String in)
This method takes a string and strips out all tags except
tags while still leaving the tag body intact. |
static java.lang.String |
stripTags(java.lang.String in,
boolean stripBRTag)
This method takes a string and strips out all tags while still leaving
the tag body intact.
|
static java.lang.String[] |
toLowerCaseWordArray(java.lang.String text)
Converts a line of text into an array of lower case words using a
BreakIterator .wordInstance(). |
static java.lang.String |
unescapeFromXML(java.lang.String string)
Unescapes the String by converting XML escape sequences back into normal
characters.
|
static java.lang.String |
URLEncode(java.lang.String original,
java.lang.String charset)
Encodes URI string.
|
static java.lang.String |
wordWrap(java.lang.String input,
int width,
java.util.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 java.lang.String |
zeroPadString(java.lang.String string,
int length)
Pads the supplied String with 0's to the specified length and returns
the result as a new String.
|
public static java.lang.String replace(java.lang.String string, java.lang.String oldString, java.lang.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 oldStringpublic static java.lang.String replaceIgnoreCase(java.lang.String line, java.lang.String oldString, java.lang.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 oldStringpublic static java.lang.String replaceIgnoreCase(java.lang.String line, java.lang.String oldString, java.lang.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 java.lang.String replace(java.lang.String line, java.lang.String oldString, java.lang.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
- Number of replaces.public static java.lang.String stripTags(java.lang.String in)
in
- the text to be converted.public static java.lang.String stripTags(java.lang.String in, boolean stripBRTag)
in
- the text to be converted.stripBRTag
- Remove BR tags.public static java.lang.String escapeHTMLTags(java.lang.String in)
in
- the text to be converted.public static java.lang.String hash(java.lang.String data)
data
- the String to compute the hash of.public static java.lang.String hash(byte[] data)
public static java.lang.String encodeHex(byte[] bytes)
bytes
- an array of bytes to convert to a hex-stringpublic static byte[] decodeHex(java.lang.String hex)
hex
- a hex encoded String to transform into a byte array.public static java.lang.String encodeBase64(java.lang.String data)
data
- a String to encode.public static java.lang.String encodeBase64(byte[] data)
data
- a byte array to encode.public static java.lang.String decodeBase64(java.lang.String data)
data
- a base64 encoded String to decode.public static java.lang.String decodeBase64(byte[] data)
data
- a base64 encode byte array to decode.public static java.lang.String URLEncode(java.lang.String original, java.lang.String charset) throws java.io.UnsupportedEncodingException
original
- the original character sequencecharset
- the protocol charsetjava.io.UnsupportedEncodingException
- unsupported character encodingpublic static java.lang.String[] toLowerCaseWordArray(java.lang.String text)
BreakIterator
.wordInstance().
This method is under the Jive Open Source Software Licensetext
- a String of text to convert into an array of wordspublic static java.lang.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 java.lang.String chopAtWord(java.lang.String string, int length, int minLength)
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, -1) 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.minLength
- the minimum length the word should be chopped at. This is
helpful
for words with no natural boundaries, ie:
"thisisareallylonglonglongword".
This must be smaller than length and can be -1 if no minLength
is wantedstring
whose length is less than or
equal to length
, and that is chopped at whitespace.public static java.lang.String chopAtWord(java.lang.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 java.lang.String chopAtWordsAround(java.lang.String input, java.lang.String[] wordList, int numChars)
Note: The wordList passed in should be lowercase.
input
- The string to parse.wordList
- The words to look for - the first one found in the string is
used.numChars
- The number of characters on either side to include in the
chop.public static java.lang.String wordWrap(java.lang.String input, int width, java.util.Locale locale)
input
- the String to reformat.width
- the maximum length of any one line.locale
- of the string to be wrapped.public static java.lang.String highlightWords(java.lang.String string, java.lang.String[] words, java.lang.String startHighlight, java.lang.String endHighlight)
string
- the String to highlight words in.words
- an array of words that should be highlighted in the string.startHighlight
- the tag that should be inserted to start highlighting.endHighlight
- the tag that should be inserted to end highlighting.public static java.lang.String escapeForXML(java.lang.String string)
string
- the string to escape.public static java.lang.String unescapeFromXML(java.lang.String string)
string
- the string to unescape.public static java.lang.String zeroPadString(java.lang.String string, int length)
string
- the original String to pad.length
- the desired length of the new padded String.public static java.lang.String dateToMillis(java.util.Date date)
date
- Date to convert to milliseconds.public static boolean isValidEmailAddress(java.lang.String addr)
addr
- the email address to validatepublic static java.lang.String keyStroke2String(javax.swing.KeyStroke key)
public static java.lang.String getKeyText(int keyCode)
public static java.lang.String makeFirstWordCaptial(java.lang.String word)
word
- public static java.lang.String modifyWildcards(java.lang.String resource)
for properties see System.getProperties()
resource
- String to modifypublic static java.lang.String getMD5Checksum(java.lang.String filepath) throws java.security.NoSuchAlgorithmException, java.io.IOException
filepath
- java.io.IOException
java.security.NoSuchAlgorithmException
java.lang.Exception
public static byte[] createChecksum(java.lang.String filename) throws java.security.NoSuchAlgorithmException, java.io.IOException
filename
- java.security.NoSuchAlgorithmException
java.io.IOException
java.lang.Exception
public static int countNumberOfOccurences(java.lang.String string, char c)
string
- c
- Integer