package reuse.util;

public class ByteCodec {
	public static byte[] hexStringToByteArray(String s) {
	    int len = s.length();
	    byte[] data = new byte[len / 2];
	    for (int i = 0; i < len; i += 2) {
	        data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
	                             + Character.digit(s.charAt(i+1), 16));
	    }
	    return data;
	}
	
	public static void main(String[] args) {
		String hex = "00 00 00 2F 00 00 00 02 00 00 00 00 00 00 00 01 53 4D 50 50 33 54 45 53 54 00\r\n" + 
				"73 65 63 72 65 74 30 38 00 53 55 42 4D 49 54 31 00 00 01 01 00";
		
		byte[] buf = ByteCodec.hexEtcStringToByteArray(hex);
		System.out.println(buf.length);
	}

	/**
	 * remove white space chars before to byte[]
	 * @param s
	 * @return
	 */
	public static byte[] hexEtcStringToByteArray(String s) {
		return ByteCodec.hexStringToByteArray(s.replaceAll("\\s", ""));
	}
}

@@ -99,20 +99,125 @@
  s) %7B%0D%0A%09
-    
+%09if (s.length() %25 2 != 0) %7B%0D%0A%09%09%09throw new IllegalArgumentException(%22must be even length: %22 + s);%0D%0A%09%09%7D%0D%0A%09%09%0D%0A%09%09
 int len 
@@ -232,20 +232,17 @@
 th();%0D%0A%09
-    
+%09
 byte%5B%5D d
@@ -268,20 +268,17 @@
 / 2%5D;%0D%0A%09
-    
+%09
 for (int
@@ -306,24 +306,18 @@
  2) %7B%0D%0A%09
-        
+%09%09
 data%5Bi /
@@ -373,39 +373,8 @@
 %3C 4)
-%0D%0A%09                            
  + C
@@ -373,32 +373,39 @@
 %3C 4) + Character
+%0D%0A%09%09%09%09%09
 .digit(s.charAt(
@@ -405,17 +405,19 @@
 charAt(i
-+
+ + 
 1), 16))
@@ -424,20 +424,14 @@
 ;%0D%0A%09
-    %7D%0D%0A%09    
+%09%7D%0D%0A%09%09
 retu

check for old length error