edu.jhu.tmaj.util
Class StringFormatUtils

java.lang.Object
  extended by edu.jhu.tmaj.util.StringFormatUtils

public final class StringFormatUtils
extends java.lang.Object

Contains utility methods for formatting Strings.


Method Summary
static byte[] decodeBase64(java.lang.String encodedString)
          Gets the byte array for base64 encoded string
static java.lang.String encodeBase64(byte[] bytes)
          Gets the String representation of a byte array using base64 encoding.
static java.lang.String formatKey(java.lang.String key)
          Converts a string into lower case and removes any underscores or hypens.
static java.lang.String getClassFormat(java.lang.Object obj)
          Returns the classname of an object in parenthesis without the package information.
static java.lang.String getExtension(java.io.File file)
           
static boolean isStringEmpty(java.lang.String string)
           
static java.lang.String truncateString(java.lang.String s, int maxLength)
          Returns a string no longer than maxLength; if s exceeds maxLength, ".." is appended after the string is truncated.
static java.lang.String zeroPad(int number, int minLength)
          Puts zeros at the beginning of a string if string length is less than min length.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

truncateString

public static java.lang.String truncateString(java.lang.String s,
                                              int maxLength)
Returns a string no longer than maxLength; if s exceeds maxLength, ".." is appended after the string is truncated.
Example: truncateString("Baltimore", 7) returns "Balti..";
Example: truncateString("Baltimore", 50) returns "Baltimore";


zeroPad

public static java.lang.String zeroPad(int number,
                                       int minLength)
Puts zeros at the beginning of a string if string length is less than min length.


encodeBase64

public static java.lang.String encodeBase64(byte[] bytes)
Gets the String representation of a byte array using base64 encoding. The purpose of Base64 encoding is to be able to represents bytes and a readable string of characters.


decodeBase64

public static byte[] decodeBase64(java.lang.String encodedString)
                           throws java.io.IOException
Gets the byte array for base64 encoded string

Throws:
java.io.IOException

getClassFormat

public static java.lang.String getClassFormat(java.lang.Object obj)
Returns the classname of an object in parenthesis without the package information. For example getClassFormat(new String("I am a String object")) would return (String), not (java.lang.String)


formatKey

public static java.lang.String formatKey(java.lang.String key)
Converts a string into lower case and removes any underscores or hypens. This purpose of this is to make similar Strings equal. For example, this method would return "imagesurl" for all of the following strings:
"ImagesURL"
"Images-URL"
"Images URL"
"Images url"
" Images Url "
This is useful if you are storing strings in a standard format.


isStringEmpty

public static boolean isStringEmpty(java.lang.String string)

getExtension

public static java.lang.String getExtension(java.io.File file)