Methods Summary |
---|
public byte[] | getData()Returns data associated with current TLV object
returns null if !isValidObject()
if (!hasValidTlvObject) return null;
byte[] ret = new byte[curDataLength];
System.arraycopy(record, curDataOffset, ret, 0, curDataLength);
return ret;
|
public int | getTag()Returns the tag for the current TLV object
Return 0 if !isValidObject()
0 and 0xff are invalid tag values
valid tags range from 1 - 0xfe
if (!hasValidTlvObject) return 0;
return record[curOffset] & 0xff;
|
public boolean | isValidObject()
return hasValidTlvObject;
|
public boolean | nextObject()
if (!hasValidTlvObject) return false;
curOffset = curDataOffset + curDataLength;
hasValidTlvObject = parseCurrentTlvObject();
return hasValidTlvObject;
|
private boolean | parseCurrentTlvObject()Updates curDataLength and curDataOffset
// 0x00 and 0xff are invalid tag values
if (record[curOffset] == 0 || (record[curOffset] & 0xff) == 0xff) {
return false;
}
try {
if ((record[curOffset + 1] & 0xff) < 0x80) {
// one byte length 0 - 0x7f
curDataLength = record[curOffset + 1] & 0xff;
curDataOffset = curOffset + 2;
} else if ((record[curOffset + 1] & 0xff) == 0x81) {
// two byte length 0x80 - 0xff
curDataLength = record[curOffset + 2] & 0xff;
curDataOffset = curOffset + 3;
} else {
return false;
}
} catch (ArrayIndexOutOfBoundsException ex) {
return false;
}
if (curDataLength + curDataOffset > tlvOffset + tlvLength) {
return false;
}
return true;
|