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 for converting String's into the hex for a given encoding and back again.


Constructor Summary
HexUtils()
           
 
Method Summary
static byte[] getBytesFromHexString(String hex)
          Given a string in strictly hex format, return the corresponding byte[].
static org.apache.commons.lang3.CharSet getHexCharSet()
           
static String[] getHexRanges()
           
static boolean isHex(char... chars)
          Return true if every character is valid hex 0-9, a-f, or A-F
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.
protected static String toString(String[] tokens)
           
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

getHexCharSet

public static final org.apache.commons.lang3.CharSet getHexCharSet()

getHexRanges

public static final String[] getHexRanges()

toString

protected static final String toString(String[] tokens)

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.


isHex

public static final boolean isHex(char... chars)
Return true if every character is valid hex 0-9, a-f, or A-F


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-2013 The Kuali Foundation. All Rights Reserved.