@Test public void testHex_InsufficientChars() throws Exception { try { Conversion.hexStringToByteArray("0d0ac"); fail(); } catch (IOException expected) { assertEquals("Odd number of characters.", expected.getMessage()); } }
public static byte[] hexStringToByteArray(String s) throws IOException { int len = s.length(); if ((len & 0x01) != 0) { throw new IOException("Odd number of characters."); } byte[] data = new byte[len / 2]; for (int i = 0; i < len; i += 2) { data[i / 2] = (byte) ((hexCharToDigit(s.charAt(i)) << 4) + hexCharToDigit(s.charAt(i + 1))); } return data; }
Conversion { public static byte[] hexStringToByteArray(String s) throws IOException { int len = s.length(); if ((len & 0x01) != 0) { throw new IOException("Odd number of characters."); } byte[] data = new byte[len / 2]; for (int i = 0; i < len; i += 2) { data[i / 2] = (byte) ((hexCharToDigit(s.charAt(i)) << 4) + hexCharToDigit(s.charAt(i + 1))); } return data; } }
Conversion { public static byte[] hexStringToByteArray(String s) throws IOException { int len = s.length(); if ((len & 0x01) != 0) { throw new IOException("Odd number of characters."); } byte[] data = new byte[len / 2]; for (int i = 0; i < len; i += 2) { data[i / 2] = (byte) ((hexCharToDigit(s.charAt(i)) << 4) + hexCharToDigit(s.charAt(i + 1))); } return data; } private  Conversion(); }
Conversion { public static byte[] hexStringToByteArray(String s) throws IOException { int len = s.length(); if ((len & 0x01) != 0) { throw new IOException("Odd number of characters."); } byte[] data = new byte[len / 2]; for (int i = 0; i < len; i += 2) { data[i / 2] = (byte) ((hexCharToDigit(s.charAt(i)) << 4) + hexCharToDigit(s.charAt(i + 1))); } return data; } private  Conversion(); static String byteToHexString(byte b); static String byteArrayToHexString(byte[] b); @Deprecated static String byteArrayToBase64String(byte[] b, int len); @Deprecated static String byteArrayToBase64String(byte[] b); @Deprecated static byte[] base64StringToByteArray(String s); static byte[] hexStringToByteArray(String s); }
Conversion { public static byte[] hexStringToByteArray(String s) throws IOException { int len = s.length(); if ((len & 0x01) != 0) { throw new IOException("Odd number of characters."); } byte[] data = new byte[len / 2]; for (int i = 0; i < len; i += 2) { data[i / 2] = (byte) ((hexCharToDigit(s.charAt(i)) << 4) + hexCharToDigit(s.charAt(i + 1))); } return data; } private  Conversion(); static String byteToHexString(byte b); static String byteArrayToHexString(byte[] b); @Deprecated static String byteArrayToBase64String(byte[] b, int len); @Deprecated static String byteArrayToBase64String(byte[] b); @Deprecated static byte[] base64StringToByteArray(String s); static byte[] hexStringToByteArray(String s);  }