Package com.complexible.common.base
Class Strings2
java.lang.Object
com.complexible.common.base.Strings2
String utilities not provided by Strings.
- Since:
- 2.0
- Version:
- 2.5
- Author:
- Michael Grove
-
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]base64Decode(String theStringToDecode) Base64 encodes the given byte array.static Stringbase64Encode(byte[] theArrayToEncode) Base64 encodes the given byte array.static booleanendsWithIgnoreCase(String str, String suffix) static StringgetRandomString(int theLength) Return a string of random characters of the specified length.static StringgetRandomString(int theLength, Random random) static Stringhex(byte[] theArray) Return the hex string value of the byte arraystatic StringindentMultiline(String input, String indentPrefix) Indent a multiline string by inserting theindentPrefixat the beginning of each line.static byte[]md5(byte[] theBytes) Returns the md5 representation of a stringstatic byte[]Returns the md5 representation of a stringstatic booleanstartsWithIgnoreCase(String str, String prefix) static StringtoTitleCase(String theStr) Convert a string to title case.static StringRemove leading and trailing spaces including newlinesstatic StringURL decode the string using the UTF8 charsetstatic StringURL decode the given string using the given Charsetstatic StringURL encode the string using the UTF8 charsetstatic StringURL encode the given string using the given Charsetstatic StringReturns the string that is one character shorter than the input string, without the last character.static StringIf the input string starts and ends with either double quotes or single quote, it is truncated, otherwise the input string is returned intact.static StringIf the input string ends with slash character "/", it is truncated, otherwise the input string is returned intact.
-
Method Details
-
toTitleCase
Convert a string to title case. So if you have "this is a sentence" this function will return "This Is A Sentence"- Parameters:
theStr- the string to convert- Returns:
- the converted string
-
hex
Return the hex string value of the byte array- Parameters:
theArray- the input array- Returns:
- the hex value of the bytes
-
md5
Returns the md5 representation of a string- Parameters:
theString- the string to md5- Returns:
- the byte representation of the md5 sum of the string
-
md5
public static byte[] md5(byte[] theBytes) Returns the md5 representation of a string- Parameters:
theBytes- the bytes to md5- Returns:
- the byte representation of the md5 sum of the string
-
getRandomString
Return a string of random characters of the specified length.- Parameters:
theLength- the size of the random string to create- Returns:
- a string of random letters
-
getRandomString
-
urlEncode
URL encode the string using the UTF8 charset- Parameters:
theString- the string to encode- Returns:
- the url encoded string
-
urlEncode
URL encode the given string using the given Charset- Parameters:
theString- the string to encodetheCharset- the charset to encode the string using- Returns:
- the string encoded with the given charset
-
urlDecode
URL decode the string using the UTF8 charset- Parameters:
theString- the string to decode- Returns:
- the decoded string
-
urlDecode
URL decode the given string using the given Charset- Parameters:
theString- the string to decodetheCharset- the charset to decode the string using- Returns:
- the string decoded with the given charset
-
base64Encode
Base64 encodes the given byte array. This utility is provided to abstract over the Sun implementation which is deprecated and marked for deletion. The implementation of this method will always work; so if the existing Sun implementation goes away, this will be switched to an appropriate implementation without requiring any changes to dependant code.- Parameters:
theArrayToEncode- the bytes to encode- Returns:
- the bytes base64 encoded
-
base64Decode
Base64 encodes the given byte array. This utility is provided to abstract over the Sun implementation which is deprecated and marked for deletion. The implementation of this method will always work; so if the existing Sun implementation goes away, this will be switched to an appropriate implementation without requiring any changes to dependant code.- Parameters:
theStringToDecode- the string to decode- Returns:
- the bytes base64 decoded
- Throws:
IOException- throw if there is an error while decoding
-
withoutLastCharacter
Returns the string that is one character shorter than the input string, without the last character. If empty String is given,IllegalArgumentExceptionis thrown. -
withoutTrailingSlash
If the input string ends with slash character "/", it is truncated, otherwise the input string is returned intact. -
indentMultiline
Indent a multiline string by inserting theindentPrefixat the beginning of each line. -
withoutQuotes
If the input string starts and ends with either double quotes or single quote, it is truncated, otherwise the input string is returned intact. -
trimNewlines
Remove leading and trailing spaces including newlines -
startsWithIgnoreCase
- Parameters:
str- a Stringprefix- a prefix- Returns:
- true if
strstarts withprefix, ignoring case sensitivity
-
endsWithIgnoreCase
- Parameters:
str- a Stringsuffix- a suffix- Returns:
- true if
strends withsuffix, ignoring case sensitivity
-