TLV parser -2
public static void parseTLV(String TAG,byte[] b) throws Exception
{
System.out.println("-------------------- TAG------------------------"+TAG);
byte[] tagBA=hexStringToByteArray(TAG);
boolean isTagExist=false;
int tagStartLoc=0;
for(int i=0;i<b.length;i++)
{
if(isTagExist)
break;
for(int j=0;j<tagBA.length;j++)
{
if(b[i+j]!=tagBA[j])
break;
if(j==tagBA.length-1)
{
isTagExist=true;
tagStartLoc=i;
}
}
}
if(isTagExist)
{
for(int i=tagStartLoc;i<b.length;i++)
System.out.println(" - "+b[i]);
byte[] bx=new byte[b.length-tagStartLoc];
System.out.println("Starting Location"+tagStartLoc);
System.arraycopy(b, tagStartLoc, bx, 0,tagBA.length);
byte[] length=new byte[1];
System.arraycopy(b, tagStartLoc+tagBA.length,length, 0,1);
System.out.println("-------------------- TAG------------------------");
String lenStr=getHexString(length);
Integer lenInt=Integer.parseInt(lenStr, 16);
byte[] data= new byte[lenInt];
System.arraycopy(b, tagStartLoc+tagBA.length+1,data, 0,lenInt);
System.out.println(getHexString(data));
}
No comments:
Post a Comment