Skip to content

Instantly share code, notes, and snippets.

@sunzcdev
Created December 18, 2018 07:52
Show Gist options
  • Save sunzcdev/53624edb8f9cd09db2fde0ed64dc79fc to your computer and use it in GitHub Desktop.
Save sunzcdev/53624edb8f9cd09db2fde0ed64dc79fc to your computer and use it in GitHub Desktop.
十六进制字符串转javaBean
private static <T> T hex2Bean(String str, Class<T> deviceAuthClass) {
try {
str = str.replace(" ", "");
byte[] array = new BigInteger(str, 16).toByteArray();
IoBuffer buffer = IoBuffer.wrap(array);
Constructor<T> cons = deviceAuthClass.getConstructor(IoBuffer.class);
return cons.newInstance(buffer);
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment