|
Compoze Software, Inc. | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.compoze.util.StringUtility
This class contains utility methods that operate on strings.
Constructor Summary | |
StringUtility()
|
Method Summary | |
static java.lang.String |
bytesToHex(byte[] data)
Convenience method to convert a byte array to a hex string. |
static java.lang.String |
byteToHex(byte data)
Convenience method to convert a byte to a hex string. |
static java.lang.String |
encode(java.lang.String sUnencodedString,
java.lang.String sFromEncoding,
java.lang.String sToEncoding)
Method description. |
static java.lang.String |
escapeQuotes(java.lang.String sUnescapedString)
This replaces the special quote characters with escaped value |
static byte[] |
getDigest(java.lang.String sStr)
Get an SHA digest of the specified string using the UTF-8 character encoding. |
static byte[] |
getDigest(java.lang.String sStr,
java.lang.String sAlgorithm)
Get a digest of the specified string using the UTF-8 character encoding. |
static byte[] |
getDigest(java.lang.String sStr,
java.lang.String sAlgorithm,
java.lang.String sEncoding)
Get a digest of the specified string. |
static long |
getDigestLong(java.lang.String sStr)
Get an SHA digest of the specified string, folding over the byte array into a long. |
static java.lang.String |
getListString(java.util.Collection items,
java.lang.String sDelim)
Creates a comma seperated list of items from a collection |
static java.util.LinkedList |
getSeparatedList(java.lang.String sListOfStrings,
java.lang.String sDelim)
From a list of strings separated by some separation character, get a linked list of the strings. |
static java.lang.String |
getStringFromInputStream(java.io.InputStream is)
Get a string from an input stream. |
static byte |
hexToByte(java.lang.String s)
Convenience method to convert a hex string to a byte. |
static byte[] |
hexToBytes(java.lang.String sHex)
Convenience method to convert a hex string to a byte array. |
static java.lang.String |
htmlEscape(java.lang.String sUnescapedString)
HTML escape a string. |
static java.lang.String |
htmlEscape(java.lang.String sUnescapedString,
java.lang.String sEncoding)
HTML escape a string. |
static boolean |
isBlank(java.lang.String sStr)
Determine if a string is null and empty. |
static void |
main(java.lang.String[] args)
Exerciser. |
static java.lang.String |
mapReplace(java.lang.String sString,
java.util.Map replacementMap,
java.lang.String sEscape)
Replace occurrences of escaped strings (variables) within a string using a hash map that maps keys to their values. |
static java.lang.String |
mapReplace(java.lang.String sString,
java.util.Map replacementMap,
java.lang.String sEscapeStart,
java.lang.String sEscapeEnd)
Replace occurrences of escaped strings (variables) within a string using a hash map that maps keys to their values. |
static java.lang.String |
mapReplace(java.lang.String sString,
java.util.Map replacementMap,
java.lang.String sEscapeStart,
java.lang.String sEscapeEnd,
boolean bDefaultToSystem)
Replace occurrences of escaped strings (variables) within a string using a hash map that maps keys to their values. |
static java.lang.String |
mapReplaceFully(java.lang.String sString,
java.util.Map replacementMap,
java.lang.String sEscapeStart,
java.lang.String sEscapeEnd,
boolean bDefaultToSystem)
Replace occurrences of escaped strings (variables) within a string using a hash map that maps keys to their values. |
static java.lang.Object |
objectFromBase64(java.lang.String str)
Gets an object from a string. |
static java.lang.Object |
objectFromBase64(java.lang.String str,
boolean bCompress)
Gets an object from a string. |
static java.lang.String |
objectToBase64(java.lang.Object serializableObj)
Gets a string from an object. |
static java.lang.String |
objectToBase64(java.lang.Object serializableObj,
boolean bCompress)
Gets a string from an object. |
static java.lang.String |
objectToString(java.lang.Object o)
Convert an object to a string using the object toString. |
static java.lang.String |
prettyTruncate(java.lang.String sStr,
int iLength)
Truncate a string after a certain number of characters and append the specified string to it. |
static java.lang.String |
prettyTruncate(java.lang.String sStr,
java.lang.String sPostfix,
int iLength)
Truncate a string after a certain number of characters and append the specified string to it. |
static java.lang.String |
replaceString(java.lang.String sOriginalString,
java.lang.String sOldString,
java.lang.String sNewString)
Replace all occurrences of a string in a string. |
static java.lang.String |
substituteAll(java.lang.String source,
java.lang.String toBeReplaced,
java.lang.String replacement)
Substitutes all occurrences of a string. |
static java.lang.String |
substituteFirst(java.lang.String source,
java.lang.String toBeReplaced,
java.lang.String replacement)
Substitutes first occurrence of a string. |
static char |
toHexChar(int i)
Convenience method to convert an int to a hex char. |
static java.lang.String |
trimChar(java.lang.String str,
char c)
Trim the given character from either end of a String. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public StringUtility()
Method Detail |
public static java.lang.String objectToBase64(java.lang.Object serializableObj) throws java.io.IOException
Serializable
object to a string by base64 encoding its serialized data. The object's
data is compressed.serializableObj
- the object to convertjava.io.IOException
- if the object could not be converted to a String
public static java.lang.String objectToBase64(java.lang.Object serializableObj, boolean bCompress) throws java.io.IOException
Serializable
object to a string by base64 encoding its serialized data.serializableObj
- the object to convertbCompress
- if true, compress the outputjava.io.IOException
- if the object could not be converted to a String
public static java.lang.Object objectFromBase64(java.lang.String str) throws java.io.IOException, java.lang.ClassNotFoundException
str
- the string containing the base64 encoded, serialized
version of the objectjava.io.IOException
- if the String
could not be converted to an objectjava.lang.ClassNotFoundException
- if the class in the String
could not
be foundpublic static java.lang.Object objectFromBase64(java.lang.String str, boolean bCompress) throws java.io.IOException, java.lang.ClassNotFoundException
str
- the string containing the base64 encoded, serialized
version of the objectbCompress
- if true, decompress the object's data as it is readjava.io.IOException
- if the String
could not be converted to an objectjava.lang.ClassNotFoundException
- if the class in the String
could not
be foundpublic static java.lang.String encode(java.lang.String sUnencodedString, java.lang.String sFromEncoding, java.lang.String sToEncoding)
public static java.lang.String byteToHex(byte data)
data
- the byte to convertpublic static java.lang.String bytesToHex(byte[] data)
data
- the byte[] to convertpublic static byte hexToByte(java.lang.String s)
s
- the string to convertpublic static byte[] hexToBytes(java.lang.String sHex)
data
- the byte[] to convertpublic static char toHexChar(int i)
i
- the int to convertpublic static java.lang.String htmlEscape(java.lang.String sUnescapedString, java.lang.String sEncoding) throws java.io.UnsupportedEncodingException
sUnescapedString
- the unescaped stringsEncoding
- the character encodingpublic static java.lang.String htmlEscape(java.lang.String sUnescapedString)
sUnescapedString
- the unescaped stringpublic static java.lang.String escapeQuotes(java.lang.String sUnescapedString)
sUnescapedString
- the unescaped stringpublic static java.lang.String getStringFromInputStream(java.io.InputStream is) throws java.io.IOException
is
- the input stream to some textjava.io.IOException
- if an i/o error occurredpublic static java.lang.String trimChar(java.lang.String str, char c)
str
- the string to trimc
- the character to trim from either endpublic static java.lang.String replaceString(java.lang.String sOriginalString, java.lang.String sOldString, java.lang.String sNewString) throws java.io.IOException
sOriginalString
- the string to do the replacement insOldString
- the string to search forsNewString
- the replacementpublic static final java.lang.String substituteAll(java.lang.String source, java.lang.String toBeReplaced, java.lang.String replacement)
public static final java.lang.String substituteFirst(java.lang.String source, java.lang.String toBeReplaced, java.lang.String replacement)
public static java.lang.String mapReplace(java.lang.String sString, java.util.Map replacementMap, java.lang.String sEscape)
sString
- the string to replace variables inreplacementMap
- the key/value pairs for replacementsEscape
- the string that appears before and after variablespublic static java.lang.String mapReplaceFully(java.lang.String sString, java.util.Map replacementMap, java.lang.String sEscapeStart, java.lang.String sEscapeEnd, boolean bDefaultToSystem)
sString
- the string to replace variables inreplacementMap
- the key/value pairs for replacementsEscapeStart
- the string that appears before variablessEscapeEnd
- the string that appears after variablesbDefaultToSystem
- if a property cannot be found, default to the system propertypublic static java.lang.String mapReplace(java.lang.String sString, java.util.Map replacementMap, java.lang.String sEscapeStart, java.lang.String sEscapeEnd)
sString
- the string to replace variables inreplacementMap
- the key/value pairs for replacementsEscapeStart
- the string that appears before variablessEscapeEnd
- the string that appears after variablespublic static java.lang.String mapReplace(java.lang.String sString, java.util.Map replacementMap, java.lang.String sEscapeStart, java.lang.String sEscapeEnd, boolean bDefaultToSystem)
sString
- the string to replace variables inreplacementMap
- the key/value pairs for replacementsEscapeStart
- the string that appears before variablessEscapeEnd
- the string that appears after variablesbDefaultToSystem
- if a property cannot be found, default to the system propertypublic static java.util.LinkedList getSeparatedList(java.lang.String sListOfStrings, java.lang.String sDelim)
sListOfStrings
- the separated list of stringssDelim
- the delimiterStringTokenizer
public static java.lang.String getListString(java.util.Collection items, java.lang.String sDelim)
items
- collection of itemssDelim
- delimiterpublic static java.lang.String objectToString(java.lang.Object o)
o
- the object to convert to stringObject.toString()
public static byte[] getDigest(java.lang.String sStr, java.lang.String sAlgorithm, java.lang.String sEncoding) throws java.security.NoSuchAlgorithmException, java.io.UnsupportedEncodingException
sStr
- the string to digestsAlgorithm
- use the specified MessageDigest
algorithmsEncoding
- use the specified character encodingjava.security.NoSuchAlgorithmException
- if the specified algorithm could not be foundjava.io.UnsupportedEncodingException
- if the specified character encoding
is not supportedpublic static byte[] getDigest(java.lang.String sStr) throws java.security.NoSuchAlgorithmException, java.io.UnsupportedEncodingException
sStr
- the string to digestjava.security.NoSuchAlgorithmException
- if the specified algorithm could not be foundjava.io.UnsupportedEncodingException
- if the specified character encoding
is not supportedpublic static byte[] getDigest(java.lang.String sStr, java.lang.String sAlgorithm) throws java.security.NoSuchAlgorithmException, java.io.UnsupportedEncodingException
sStr
- the string to digestsAlgorithm
- use the specified MessageDigest
algorithmjava.security.NoSuchAlgorithmException
- if the specified algorithm could not be foundjava.io.UnsupportedEncodingException
- if the specified character encoding
is not supportedpublic static long getDigestLong(java.lang.String sStr) throws java.security.NoSuchAlgorithmException, java.io.UnsupportedEncodingException
sStr
- the string to digestjava.security.NoSuchAlgorithmException
- if the specified algorithm could not be foundjava.io.UnsupportedEncodingException
- if the specified character encoding
is not supportedpublic static boolean isBlank(java.lang.String sStr)
sStr
- the string to evaluatepublic static java.lang.String prettyTruncate(java.lang.String sStr, java.lang.String sPostfix, int iLength)
sStr
- the original stringsPostfix
- the string to put at the end of the original stringiLength
- the maximum length of the result (string plus postfix)public static java.lang.String prettyTruncate(java.lang.String sStr, int iLength)
sStr
- the original stringiLength
- the maximum length of the result (string plus postfix)public static void main(java.lang.String[] args)
args
- arguments (none taken)
|
Compoze Software, Inc. | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |