pulse - the web application framework Get pulse at SourceForge.net. Fast, secure and Free Open Source software downloads Ohloh project report for pulse-java

org.torweg.pulse.util
Class StringUtils

java.lang.Object
  extended by org.torweg.pulse.util.StringUtils

public final class StringUtils
extends java.lang.Object

contains static utitity methods which are useful, when working with Strings.

Version:
$Revision: 2022 $
Author:
Thomas Weber

Nested Class Summary
static class StringUtils.StringElementIterator
          Simple ListIterator<String> that operates on a String split by a regex.
 
Method Summary
static java.lang.String digest16(byte[] bytes)
          hashes the byte[] using <em>SHA-512</em>.
static java.lang.String digest16(java.lang.String str)
          hashes the given string using <em>SHA-512</em>.
static java.lang.String digest62(byte[] bytes)
          hashes the byte[] using <em>SHA-512</em>.
static java.lang.String digest62(java.lang.String str)
          hashes the string using <em>SHA-512</em>.
static java.math.BigInteger fromBase62String(java.lang.String base62)
          returns the BigInteger represented by the given base 62 string.
static java.lang.String getEncoding(java.lang.String s)
          returns the encoding of the given String.
static java.lang.String getStackTrace(java.lang.Throwable t)
          returns the stack trace of the given Throwable as a string.
static java.lang.String getString(java.lang.Object o)
          returns either the given object's string representation or "null", if the given object is null.
static java.lang.String insertFractionDot(java.lang.String s, int pos)
          Inserts a fraction-dot into the given string at after the given position (counting from the back) filling the string up with 0s (zeros) if too short.
static java.lang.StringBuilder insertFromBack(java.lang.String s, int pos, java.lang.String insert, java.lang.String fill)
          Inserts the given string insert at the specified position pos from the back of the string.
static java.lang.String maxLength(java.lang.String s, int l)
          ensures that the given String does not exceed the given maximum length, cutting off all characters exceeding characters.
static java.lang.String toBase62String(java.math.BigInteger token)
          returns a base 62 string for the given BigInteger.
static java.lang.String toBase62String(byte[] bytes)
          returns a base 62 string for the given byte array.
static java.lang.String toHexString(byte[] bs)
          turns a given byte[] into a string of hexadecimal numbers.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getEncoding

public static java.lang.String getEncoding(java.lang.String s)
returns the encoding of the given String.

Parameters:
s - the string to inspect
Returns:
the encoding

toHexString

public static java.lang.String toHexString(byte[] bs)
turns a given byte[] into a string of hexadecimal numbers.

For example 127, 126 get FFFE.

Parameters:
bs - the bytes
Returns:
the hexadecimal string

toBase62String

public static java.lang.String toBase62String(java.math.BigInteger token)
returns a base 62 string for the given BigInteger.

Parameters:
token - the number to be converted
Returns:
the base 62 representation

toBase62String

public static java.lang.String toBase62String(byte[] bytes)
returns a base 62 string for the given byte array.

Parameters:
bytes - the byte array
Returns:
the base 62 string

fromBase62String

public static java.math.BigInteger fromBase62String(java.lang.String base62)
returns the BigInteger represented by the given base 62 string.

Parameters:
base62 - the base 62 encoded value
Returns:
the BigInteger represented by the given base 62 string

digest16

public static java.lang.String digest16(java.lang.String str)
                                 throws java.security.NoSuchAlgorithmException
hashes the given string using <em>SHA-512</em>.

Parameters:
str - the string
Returns:
the hash value as an hexadecimal string
Throws:
java.security.NoSuchAlgorithmException - if the hashing algorithm is not available

digest16

public static java.lang.String digest16(byte[] bytes)
                                 throws java.security.NoSuchAlgorithmException
hashes the byte[] using <em>SHA-512</em>.

Parameters:
bytes - the bytes
Returns:
the hash value as an hexadecimal string
Throws:
java.security.NoSuchAlgorithmException - if the hashing algorithm is not available

digest62

public static java.lang.String digest62(java.lang.String str)
                                 throws java.security.NoSuchAlgorithmException
hashes the string using <em>SHA-512</em>.

Parameters:
str - the string
Returns:
the hash value as a base 62 string
Throws:
java.security.NoSuchAlgorithmException - if the hashing algorithm is not available

digest62

public static java.lang.String digest62(byte[] bytes)
                                 throws java.security.NoSuchAlgorithmException
hashes the byte[] using <em>SHA-512</em>.

Parameters:
bytes - the bytes
Returns:
the hash value as a base 62 string
Throws:
java.security.NoSuchAlgorithmException - if the hashing algorithm is not available

getStackTrace

public static java.lang.String getStackTrace(java.lang.Throwable t)
returns the stack trace of the given Throwable as a string.

Parameters:
t - the throwable
Returns:
the stack trace of the given Throwable as a string

insertFractionDot

public static java.lang.String insertFractionDot(java.lang.String s,
                                                 int pos)
Inserts a fraction-dot into the given string at after the given position (counting from the back) filling the string up with 0s (zeros) if too short.

Parameters:
s - the string to format
pos - the position to insert the fraction-dot
Returns:
the formatted string

insertFromBack

public static java.lang.StringBuilder insertFromBack(java.lang.String s,
                                                     int pos,
                                                     java.lang.String insert,
                                                     java.lang.String fill)
Inserts the given string insert at the specified position pos from the back of the string.

Parameters:
s - the string to be formatted
pos - the position
insert - the string to insert
fill - the fill
Returns:
a StringBuilder

maxLength

public static java.lang.String maxLength(java.lang.String s,
                                         int l)
ensures that the given String does not exceed the given maximum length, cutting off all characters exceeding characters.

null values will be converted to empty strings.

Parameters:
s - the string
l - the maximum length
Returns:
a string that is guaranteed to be less than or equal in length to the given maximum length

getString

public static java.lang.String getString(java.lang.Object o)
returns either the given object's string representation or "null", if the given object is null.

Parameters:
o - the object
Returns:
either the given object's string representation or "null", if the given object is null