Java String to convertStringToPrimaryKey(String keyString)

Here you can find the source of convertStringToPrimaryKey(String keyString)

Description

Converts a String to the 192-bit primary key.

Converts the given key to lower case prior to conversion to binary.

License

Open Source License

Parameter

Parameter Description
keyString the key string to convert.

Return

a 192-bit primary key.

Declaration

public static byte[] convertStringToPrimaryKey(String keyString) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from   www. j a  v  a2 s .c o m*/
     * <p>Converts a <code>String</code> to the 192-bit primary key.</p>
     * Converts the given key to lower case prior to conversion to binary.
     * 
     * @param keyString the key string to convert.
     * 
     * @return a 192-bit primary key.
     */
    public static byte[] convertStringToPrimaryKey(String keyString) {

        if ((keyString != null) && (!"".equals(keyString))) {

            keyString = keyString.toLowerCase();
            byte[] bArray = new byte[(keyString.length() / 2)];

            for (int i = 0; i < bArray.length; i++) {
                bArray[i] = (byte) Integer.parseInt(keyString.substring(i * 2, i * 2 + 2), 16);
            }
            return bArray;
        }
        return null;
    }
}

Related

  1. convertStringToFloat(String str)
  2. convertStringToId(String s)
  3. convertStringToIntDef(String string, int defaultValue)
  4. convertStringToLiteral(String className, String value)
  5. convertStringToObject(String value, Class type)
  6. convertStringToPrimitive(Object object, Class toType)
  7. convertStringToPrimitive(String value, Class destinationClass)
  8. convertStringToSafeFilename(String s)
  9. convertStringToValue(String txt, Class klass)