Skip to content

Instantly share code, notes, and snippets.

@sujee
Created August 25, 2011 00:32
Show Gist options
  • Save sujee/1169662 to your computer and use it in GitHub Desktop.
Save sujee/1169662 to your computer and use it in GitHub Desktop.
hadoop utilities : StringUtil 2
import org.apache.hadoop.util.StringUtils;
// ----------------- String Utils : bytes <--> hex ---------
String s = "aj89y1_xxy";
byte[] b = s.getBytes();
String hex = StringUtils.byteToHexString(b);
byte[] b2 = StringUtils.hexStringToByte(hex);
String s2 = new String(b2);
System.out.println(s + " --> " + hex + " <-- " + s2);
/* output:
aj89y1_xxy --> 616a383979315f787879 <-- aj89y1_xxy
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment