FileDocCategorySizeDatePackage
Utils.javaAPI DocphoneME MR2 API (J2ME)4785Wed May 02 18:00:42 BST 2007gov.nist.core

Utils

public class Utils extends Object
A set of utilities that compensate for things that are missing in CLDC 1.0
version
1.0

Fields Summary
private static MessageDigest
messageDigest
Instatce of MessageDigest
private static final char[]
toHex
to hex converter
Constructors Summary
Methods Summary
public static intcompareToIgnoreCase(java.lang.String s1, java.lang.String s2)
Compares two strings lexicographically, ignoring case considerations.

param
s1 string to compare
param
s2 string to compare.
return
1, -1, 0 as in compare To

    
                                  
           
	// System.out.println(s1+" "+s2);
	String su1 = s1.toUpperCase();
	String su2 = s2.toUpperCase();
	return su1.compareTo(su2);
    
public static byte[]digest(byte[] digestBytes)
Do an MD5 Digest.

param
digestBytes input data
return
MD5 hash value of the input data

        try {
            messageDigest = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException ex) {
            if (Logging.REPORT_LEVEL <= Logging.ERROR) {
                Logging.report(Logging.ERROR, LogChannels.LC_JSR180,
                    "Exception on MessageDigest instance creating " + ex);
            }
        }
    
        byte[] returnValue;

        returnValue = new byte[messageDigest.getDigestLength()];
        messageDigest.update(digestBytes, 0, digestBytes.length);

        try {
            messageDigest.digest(returnValue, 0, returnValue.length);
        } catch (DigestException de) {
            // nothing to do
        }

        return returnValue;
    
public static booleanequalsIgnoreCase(java.lang.String s1, java.lang.String s2)
Compares two strings lexicographically.

param
s1 string to compare
param
s2 string to compare.
return
1,-1,0 as in compare To

	return s1.toLowerCase().equals(s2.toLowerCase());
    
public static java.lang.StringgenerateTag()
Generate a tag for a FROM header or TO header. Just return a random 4 digit integer (should be enough to avoid any clashes!)

return
a string that can be used as a tag parameter.

        return new Long(System.currentTimeMillis()).toString();
    
public static java.lang.StringgetQuotedString(java.lang.String str)
Put quotes around a string and return it.

return
a quoted string
param
str string to be quoted

	return  '"" + str + '"";
    
public static java.lang.StringreduceString(java.lang.String input)
Squeeze out white space from a string and return the reduced string.

param
input input string to sqeeze.
return
String a reduced string.

	String newString = input.toLowerCase();
	int len = newString.length();
	String retval = "";
	for (int i = 0; i < len; i++) {
	    if (newString.charAt(i) == ' "
		|| newString.charAt(i) == '\t")
		continue;
	    else retval += newString.charAt(i);
	}
	return retval;
    
public static java.lang.StringtoHexString(byte[] b)
convert an array of bytes to an hexadecimal string

return
a string
param
b bytes array to convert to a hexadecimal string

	int pos = 0;
	char[] c = new char[b.length*2];
	for (int i = 0; i < b.length; i++) {
	    c[pos++] = toHex[(b[i] >> 4) & 0x0F];
	    c[pos++] = toHex[b[i] & 0x0f];
	}
	return new String(c);