org.kuali.common.util
Class HexUtils

java.lang.Object
  extended by org.kuali.common.util.HexUtils

public class HexUtils
extends Object

A few (highly inefficient) methods that, when given an encoding, can convert Java String's into the hex for that encoding and also convert the hex back into the original string.


Constructor Summary
HexUtils()
           
 
Method Summary
static byte[] getBytesFromHexString(String hex)
          Given a string in strictly hex format, return the corresponding byte[].
static String toHexString(byte[] bytes)
          Convert each byte into its 2 digit hexadecimal form.
static String toHexString(String string, String encoding)
          Convert string into a byte[] using the specified encoding, then convert each byte into its 2 digit hexadecimal form.
static String toStringFromHex(String hex, String encoding)
          Given a string in strictly hex format and the encoding that was used to produce the hex, convert it back to a Java String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HexUtils

public HexUtils()
Method Detail

toHexString

public static String toHexString(String string,
                                 String encoding)
                          throws UnsupportedEncodingException
Convert string into a byte[] using the specified encoding, then convert each byte into its 2 digit hexadecimal form.

Throws:
UnsupportedEncodingException

toHexString

public static String toHexString(byte[] bytes)
Convert each byte into its 2 digit hexadecimal form.


getBytesFromHexString

public static final byte[] getBytesFromHexString(String hex)
Given a string in strictly hex format, return the corresponding byte[]. strictly hex in the context of this method means that the string:
1 - Contains only the characters a-f, A-F, and 0-9
2 - Its length is an even number.


toStringFromHex

public static final String toStringFromHex(String hex,
                                           String encoding)
                                    throws UnsupportedEncodingException
Given a string in strictly hex format and the encoding that was used to produce the hex, convert it back to a Java String. strictly hex in the context of this method means that the string:
1 - Contains only the characters a-f, A-F, and 0-9
2 - Its length is an even number.

Throws:
UnsupportedEncodingException


Copyright © 2010-2012 The Kuali Foundation. All Rights Reserved.