org.ckkloverdos.string
Class StringUtil

java.lang.Object
  extended by org.ckkloverdos.string.StringUtil

public final class StringUtil
extends java.lang.Object

Utility, string-based methods.

Author:
Christos KK Loverdos

Field Summary
static java.util.regex.Pattern DOT_PATTERN
           
static java.lang.String EMPTY_STRING
          ""
static char[] HEX_DIGITS
          {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}
static java.lang.String UTF8
          UTF-8
 
Method Summary
static java.lang.String getStringPart(java.lang.String str, java.lang.String regularExpression, int index)
          Splits str according to the given regularExpression and returns the indexth item.
static java.lang.String getStringUID()
          Generates a Unique ID in string form.
static java.lang.String getStringUID(java.util.Random random)
          Generates a Unique ID in string form by using the provided random number generator.
static java.lang.String getTextLine(java.lang.String text, int n)
          Splits the provided text into lines and returns the nth line.
static char hexToAscii(int h)
          Returns the ASCII character represententation of the hexadecimal value h.
static java.lang.String messageDigest(java.lang.String input)
          Computes a message digest for the given input.
static java.lang.String messageDigest(java.lang.String input, java.lang.String algorithm)
          Computes a message digest for the given input, by using the specified algorithm.
static java.lang.String messageDigest(java.lang.String msg, java.lang.String algorithm, java.lang.String encoding)
          Computes a message digest for the given input, by using the specified algorithm.
static java.lang.String safeRemoveSuffix(java.lang.String str, java.lang.String suffix)
          Safely removes the suffix from str.
static java.lang.String safeRemoveSuffixRepeat(java.lang.String str, java.lang.String suffix)
          Safely removes the suffix from str.
static java.lang.String[] splitDots(java.lang.String s)
          Splits the input by dots.
static java.lang.String substring(java.lang.String s, int beginIndex)
          GC-friendly version of String.substring(int).
static java.lang.String substring(java.lang.String s, int beginIndex, int endIndex)
          GC-friendly version of String.substring(int, int).
static java.lang.String toHex(byte b)
          Returns the hex representation of the input.
static java.lang.String toHex(byte[] b)
          Returns the hex representation of the input.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DOT_PATTERN

public static java.util.regex.Pattern DOT_PATTERN

UTF8

public static final java.lang.String UTF8
UTF-8

See Also:
Constant Field Values

EMPTY_STRING

public static final java.lang.String EMPTY_STRING
""

See Also:
Constant Field Values

HEX_DIGITS

public static final char[] HEX_DIGITS
{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}

Method Detail

toHex

public static java.lang.String toHex(byte[] b)
Returns the hex representation of the input.

Parameters:
b -

toHex

public static java.lang.String toHex(byte b)
Returns the hex representation of the input.

Parameters:
b -

hexToAscii

public static char hexToAscii(int h)
Returns the ASCII character represententation of the hexadecimal value h.

Parameters:
h -

messageDigest

public static java.lang.String messageDigest(java.lang.String input)
Computes a message digest for the given input.

Parameters:
input -

messageDigest

public static java.lang.String messageDigest(java.lang.String input,
                                             java.lang.String algorithm)
Computes a message digest for the given input, by using the specified algorithm.

Parameters:
input -
algorithm -

messageDigest

public static java.lang.String messageDigest(java.lang.String msg,
                                             java.lang.String algorithm,
                                             java.lang.String encoding)
Computes a message digest for the given input, by using the specified algorithm. The encoding is used to obtain byte values from the input, by using String.getBytes(String). If the algorithm is null, then SHA1 is used. If the encoding is null, then UTF8 is used.

Parameters:
msg -
algorithm -
encoding -

safeRemoveSuffixRepeat

public static java.lang.String safeRemoveSuffixRepeat(java.lang.String str,
                                                      java.lang.String suffix)
Safely removes the suffix from str. This is performed until str no more ends with suffix. If any of the input is null, then a safe value for str is returned.

Parameters:
str -
suffix -

getStringPart

public static java.lang.String getStringPart(java.lang.String str,
                                             java.lang.String regularExpression,
                                             int index)
Splits str according to the given regularExpression and returns the indexth item. It returns null in case of an ArrayIndexOutOfBoundsException, null.

Parameters:
str -
regularExpression -
index -

safeRemoveSuffix

public static java.lang.String safeRemoveSuffix(java.lang.String str,
                                                java.lang.String suffix)
Safely removes the suffix from str. This is performed once, in contrast to safeRemoveSuffixRepeat(String, String). If any of the input is null, then a safe value for str is returned.

Parameters:
str -
suffix -

substring

public static java.lang.String substring(java.lang.String s,
                                         int beginIndex)
GC-friendly version of String.substring(int). See this bug

Parameters:
s -
beginIndex -

substring

public static java.lang.String substring(java.lang.String s,
                                         int beginIndex,
                                         int endIndex)
GC-friendly version of String.substring(int, int). See this bug

Parameters:
s -
beginIndex -
endIndex -

splitDots

public static java.lang.String[] splitDots(java.lang.String s)
Splits the input by dots.

Parameters:
s -

getStringUID

public static java.lang.String getStringUID()
Generates a Unique ID in string form.


getStringUID

public static java.lang.String getStringUID(java.util.Random random)
Generates a Unique ID in string form by using the provided random number generator.

Parameters:
random -

getTextLine

public static java.lang.String getTextLine(java.lang.String text,
                                           int n)
Splits the provided text into lines and returns the nth line. Line numbering starts from one.

Parameters:
text -
n -


Copyright © 1999-2007 Christos KK Loverdos. All Rights Reserved.