Package com.complexible.common.base
Class Strings2
- java.lang.Object
-
- com.complexible.common.base.Strings2
-
public final class Strings2 extends java.lang.ObjectString utilities not provided by
Strings.- Since:
- 2.0
- Version:
- 2.5
- Author:
- Michael Grove
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]base64Decode(java.lang.String theStringToDecode)Base64 encodes the given byte array.static java.lang.Stringbase64Encode(byte[] theArrayToEncode)Base64 encodes the given byte array.static booleanendsWithIgnoreCase(java.lang.String str, java.lang.String suffix)static java.lang.StringgetRandomString(int theLength)Return a string of random characters of the specified length.static java.lang.StringgetRandomString(int theLength, java.util.Random random)static java.lang.Stringhex(byte[] theArray)Return the hex string value of the byte arraystatic java.lang.StringindentMultiline(java.lang.String input, java.lang.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[]md5(java.lang.String theString)Returns the md5 representation of a stringstatic booleanstartsWithIgnoreCase(java.lang.String str, java.lang.String prefix)static java.lang.StringtoTitleCase(java.lang.String theStr)Convert a string to title case.static java.lang.StringtrimNewlines(java.lang.String s)Remove leading and trailing spaces including newlinesstatic java.lang.StringurlDecode(java.lang.String theString)URL decode the string using the UTF8 charsetstatic java.lang.StringurlDecode(java.lang.String theString, java.nio.charset.Charset theCharset)URL decode the given string using the given Charsetstatic java.lang.StringurlEncode(java.lang.String theString)URL encode the string using the UTF8 charsetstatic java.lang.StringurlEncode(java.lang.String theString, java.nio.charset.Charset theCharset)URL encode the given string using the given Charsetstatic java.lang.StringwithoutLastCharacter(java.lang.String s)Returns the string that is one character shorter than the input string, without the last character.static java.lang.StringwithoutQuotes(java.lang.String s)If the input string starts and ends with either double quotes or single quote, it is truncated, otherwise the input string is returned intact.static java.lang.StringwithoutTrailingSlash(java.lang.String s)If the input string ends with slash character "/", it is truncated, otherwise the input string is returned intact.
-
-
-
Method Detail
-
toTitleCase
public static java.lang.String toTitleCase(java.lang.String theStr)
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
public static java.lang.String hex(byte[] theArray)
Return the hex string value of the byte array- Parameters:
theArray- the input array- Returns:
- the hex value of the bytes
-
md5
public static byte[] md5(java.lang.String theString)
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
public static java.lang.String getRandomString(int theLength)
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
public static java.lang.String getRandomString(int theLength, java.util.Random random)
-
urlEncode
public static java.lang.String urlEncode(java.lang.String theString)
URL encode the string using the UTF8 charset- Parameters:
theString- the string to encode- Returns:
- the url encoded string
-
urlEncode
public static java.lang.String urlEncode(java.lang.String theString, java.nio.charset.Charset theCharset)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
public static java.lang.String urlDecode(java.lang.String theString)
URL decode the string using the UTF8 charset- Parameters:
theString- the string to decode- Returns:
- the decoded string
-
urlDecode
public static java.lang.String urlDecode(java.lang.String theString, java.nio.charset.Charset theCharset)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
public static java.lang.String base64Encode(byte[] theArrayToEncode)
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
public static byte[] base64Decode(java.lang.String theStringToDecode) throws java.io.IOExceptionBase64 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:
java.io.IOException- throw if there is an error while decoding
-
withoutLastCharacter
public static java.lang.String withoutLastCharacter(java.lang.String s)
Returns the string that is one character shorter than the input string, without the last character. If empty String is given,IllegalArgumentExceptionis thrown.
-
withoutTrailingSlash
public static java.lang.String withoutTrailingSlash(java.lang.String s)
If the input string ends with slash character "/", it is truncated, otherwise the input string is returned intact.
-
indentMultiline
public static java.lang.String indentMultiline(java.lang.String input, java.lang.String indentPrefix)Indent a multiline string by inserting theindentPrefixat the beginning of each line.
-
withoutQuotes
public static java.lang.String withoutQuotes(java.lang.String s)
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
public static java.lang.String trimNewlines(java.lang.String s)
Remove leading and trailing spaces including newlines
-
startsWithIgnoreCase
public static boolean startsWithIgnoreCase(java.lang.String str, java.lang.String prefix)- Parameters:
str- a Stringprefix- a prefix- Returns:
- true if
strstarts withprefix, ignoring case sensitivity
-
endsWithIgnoreCase
public static boolean endsWithIgnoreCase(java.lang.String str, java.lang.String suffix)- Parameters:
str- a Stringsuffix- a suffix- Returns:
- true if
strends withsuffix, ignoring case sensitivity
-
-