|
Compoze Software, Inc. | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.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 convert
java.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 output
java.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 object
java.io.IOException
- if the String
could not be converted to an object
java.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 read
java.io.IOException
- if the String
could not be converted to an object
java.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 convert
public static java.lang.String bytesToHex(byte[] data)
data
- the byte[] to convert
public static byte hexToByte(java.lang.String s)
s
- the string to convert
public static byte[] hexToBytes(java.lang.String sHex)
public static char toHexChar(int i)
i
- the int to convert
public static java.lang.String htmlEscape(java.lang.String sUnescapedString, java.lang.String sEncoding) throws java.io.UnsupportedEncodingException
sUnescapedString
- the unescaped stringsEncoding
- the character encoding
java.io.UnsupportedEncodingException
public static java.lang.String htmlEscape(java.lang.String sUnescapedString)
sUnescapedString
- the unescaped string
public static java.lang.String escapeQuotes(java.lang.String sUnescapedString)
sUnescapedString
- the unescaped string
public static java.lang.String getStringFromInputStream(java.io.InputStream is) throws java.io.IOException
is
- the input stream to some text
java.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 end
public 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 replacement
java.io.IOException
public 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 variables
public 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 property
public 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 variables
public 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 property
public static java.util.LinkedList getSeparatedList(java.lang.String sListOfStrings, java.lang.String sDelim)
sListOfStrings
- the separated list of stringssDelim
- the delimiter
StringTokenizer
public static java.lang.String getListString(java.util.Collection items, java.lang.String sDelim)
items
- collection of itemssDelim
- delimiter
public static java.lang.String objectToString(java.lang.Object o)
o
- the object to convert to string
Object.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 encoding
java.security.NoSuchAlgorithmException
- if the specified algorithm could not be found
java.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 digest
java.security.NoSuchAlgorithmException
- if the specified algorithm could not be found
java.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
algorithm
java.security.NoSuchAlgorithmException
- if the specified algorithm could not be found
java.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 digest
java.security.NoSuchAlgorithmException
- if the specified algorithm could not be found
java.io.UnsupportedEncodingException
- if the specified character encoding
is not supportedpublic static boolean isBlank(java.lang.String sStr)
sStr
- the string to evaluate
public 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: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |