public static byte[] hexStreamToByteArray(String hexStream){
  int length=hexStream.length();
  byte[] data=new byte[length / 2];
  for (int i=0; i < length; i+=2) {
    data[i / 2]=(byte)((Character.digit(hexStream.charAt(i),16) << 4) + Character.digit(hexStream.charAt(i + 1),16));
  }
  return data;
}

public static byte [ ] hexStreamToByteArray ( String hexStream ) { int length = hexStream . length ( ) ; byte [ ] data = new byte [ length / 2 ] ; for ( int i = 0 ; i < length ; i += 2 ) { data [ i / 2 ] = ( byte ) ( ( Character . digit ( hexStream . charAt ( i ) , 16 ) << 4 ) + Character . digit ( hexStream . charAt ( i + 1 ) , 16 ) ) ; } return data ; }
takes a hex stream and returns the corresponding byte array .
