Java Utililty Methods XML Hex

List of utility methods to do XML Hex

Description

The list of methods to do XML Hex are organized into topic(s).

Method

byte[]hexStringToByteArray(String hex)
hex String To Byte Array
return DatatypeConverter.parseHexBinary(hex);
byte[]hexStringToByteArray(String s)
Converts a hex string to a byte array.
s = s.toUpperCase();
return DatatypeConverter.parseHexBinary(s);
byte[]hexStringToBytes(String text)
hex String To Bytes
text = text.replace(" ", "");
if (text.length() % 2 == 1) {
    text = text.substring(0, text.length() - 1) + "0" + text.charAt(text.length() - 1);
return DatatypeConverter.parseHexBinary(text);
byte[]hexToBytes(final String s)
Converts the passed hex string to a byte array
if (s == null || s.isEmpty()) {
    return null;
String id = s;
if (id.length() % 2 > 0) {
    id = "0" + id;
return DatatypeConverter.parseHexBinary(id);
...
StringhexToString(String str)
Converts a hexadecimal String to the equivalent lexical representation.
return new String(DatatypeConverter.parseHexBinary(str));
StringprintHexBinary(byte[] in)
Wrapper around DatatypeConverter#printHexBinary(byte[]) to prevent NullPointerException
return in == null ? "null" : DatatypeConverter.printHexBinary(in);
StringprintHexBinary(final byte[] deviceMessage)
print Hex Binary
if (deviceMessage == null) {
    return null;
} else {
    return DatatypeConverter.printHexBinary(deviceMessage).toLowerCase();
StringreadHexString(ByteBuffer buf)
read Hex String
return readHexString(buf, 0);
Stringsha1Hex(final String text)
sha Hex
try {
    final byte[] bytesOfMessage = text.getBytes("UTF-8");
    final MessageDigest md = MessageDigest.getInstance("SHA1");
    final byte[] digest = md.digest(bytesOfMessage);
    return DatatypeConverter.printHexBinary(digest).toLowerCase();
} catch (Exception e) {
    throw new RuntimeException();
Stringsha1Hex(String data)
sha Hex
MessageDigest digest = null;
try {
    digest = MessageDigest.getInstance("SHA-1");
} catch (NoSuchAlgorithmException e) {
    throw new RuntimeException(e);
try {
    digest.update(data.getBytes("utf8"));
...