Here you can find the source of toByteBuffer(String hexStr)
public static ByteBuffer toByteBuffer(String hexStr)
//package com.java2s; //License from project: Open Source License import java.nio.ByteBuffer; public class Main { public static ByteBuffer toByteBuffer(String hexStr) { if (hexStr == null || hexStr.length() == 0) { return null; }//from ww w .j a v a 2 s . c o m if (hexStr.length() % 2 != 0) { throw new IllegalArgumentException("Invalid hex value."); } byte[] ba = new byte[hexStr.length() / 2]; for (int i = 0; i < ba.length; i++) { ba[i] = (byte) Integer.parseInt(hexStr.substring(2 * i, 2 * i + 2), 16); } ByteBuffer buffer = ByteBuffer.allocate(ba.length); buffer.clear(); buffer.put(ba); buffer.flip(); return buffer; } }