Package com.complexible.common.base

# Class Strings2

java.lang.Object
com.complexible.common.base.Strings2

public final class Strings2 extends Object

String utilities not provided by `Strings`.

Since:
  2.0
Version:
  2.5
Author:
  Michael Grove

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static byte[]`
  `base64Decode(String theStringToDecode)`
  Base64 encodes the given byte array.
  `static String`
  `base64Encode(byte[] theArrayToEncode)`
  Base64 encodes the given byte array.
  `static boolean`
  `endsWithIgnoreCase(String str, String suffix)`
  `static String`
  `getRandomString(int theLength)`
  Return a string of random characters of the specified length.
  `static String`
  `getRandomString(int theLength, Random random)`
  `static String`
  `hex(byte[] theArray)`
  Return the hex string value of the byte array
  `static String`
  `indentMultiline(String input, String indentPrefix)`
  Indent a multiline string by inserting the `indentPrefix` at the beginning of each line.
  `static byte[]`
  `md5(byte[] theBytes)`
  Returns the md5 representation of a string
  `static byte[]`
  `md5(String theString)`
  Returns the md5 representation of a string
  `static boolean`
  `startsWithIgnoreCase(String str, String prefix)`
  `static String`
  `toTitleCase(String theStr)`
  Convert a string to title case.
  `static String`
  `trimNewlines(String s)`
  Remove leading and trailing spaces including newlines
  `static String`
  `urlDecode(String theString)`
  URL decode the string using the UTF8 charset
  `static String`
  `urlDecode(String theString, Charset theCharset)`
  URL decode the given string using the given Charset
  `static String`
  `urlEncode(String theString)`
  URL encode the string using the UTF8 charset
  `static String`
  `urlEncode(String theString, Charset theCharset)`
  URL encode the given string using the given Charset
  `static String`
  `withoutLastCharacter(String s)`
  Returns the string that is one character shorter than the input string, without the last character.
  `static String`
  `withoutQuotes(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 String`
  `withoutTrailingSlash(String s)`
  If the input string ends with slash character "/", it is truncated, otherwise the input string is returned intact.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### toTitleCase

    public static String toTitleCase(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 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(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 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 String getRandomString(int theLength, Random random)

  - ### urlEncode

    public static String urlEncode(String theString)
    URL encode the string using the UTF8 charset
    Parameters:
      `theString` - the string to encode
    Returns:
      the url encoded string

  - ### urlEncode

    public static String urlEncode(String theString, Charset theCharset)
    URL encode the given string using the given Charset
    Parameters:
      `theString` - the string to encode
      `theCharset` - the charset to encode the string using
    Returns:
      the string encoded with the given charset

  - ### urlDecode

    public static String urlDecode(String theString)
    URL decode the string using the UTF8 charset
    Parameters:
      `theString` - the string to decode
    Returns:
      the decoded string

  - ### urlDecode

    public static String urlDecode(String theString, Charset theCharset)
    URL decode the given string using the given Charset
    Parameters:
      `theString` - the string to decode
      `theCharset` - the charset to decode the string using
    Returns:
      the string decoded with the given charset

  - ### base64Encode

    public static 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(String theStringToDecode) throws IOException
    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

    public static String withoutLastCharacter(String s)
    Returns the string that is one character shorter than the input string, without the last character. If empty String is given, `IllegalArgumentException` is thrown.

  - ### withoutTrailingSlash

    public static String withoutTrailingSlash(String s)
    If the input string ends with slash character "/", it is truncated, otherwise the input string is returned intact.

  - ### indentMultiline

    public static String indentMultiline(String input, String indentPrefix)
    Indent a multiline string by inserting the `indentPrefix` at the beginning of each line.

  - ### withoutQuotes

    public static String withoutQuotes(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 String trimNewlines(String s)
    Remove leading and trailing spaces including newlines

  - ### startsWithIgnoreCase

    public static boolean startsWithIgnoreCase(String str, String prefix)
    Parameters:
      `str` - a String
      `prefix` - a prefix
    Returns:
      true if `str` starts with `prefix`, ignoring case sensitivity

  - ### endsWithIgnoreCase

    public static boolean endsWithIgnoreCase(String str, String suffix)
    Parameters:
      `str` - a String
      `suffix` - a suffix
    Returns:
      true if `str` ends with `suffix`, ignoring case sensitivity