|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectes.uc3m.it.xbe32.tlv.TLVParser
This class allows the TLVs of a XBE32-encoded stream or buffer to be parsed.
For each TLV parsed, one or more parsing events are generated, and sent to
the registered TLVParseListener
, if any.
For example, parsing the following XBE32-encoded stream:
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 0 |C|E| <EXT COMPLEX TLV> | <UNSPECIFIED LENGTH> | DFFF 0000 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 4 | <Ext Id TLV> | Length = 8 | 2CFF 0008 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 8 | 0x00000001 | 0000 0001 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 12 |C| Type = 0xA602 | Length = 5 | A602 0005 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 16 | true | | FF00 0000 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 20 | <EXT ATTRIBUTE TLV> | LENGTH = 28 | 1F00 001C +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 24 | <Ext Name TLV> | Length = 7 | 21FF 0007 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 28 | 0xC2 | 0x81 | 'b' | | C281 6200 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 32 | <Ext Int16 Value TLV> | Length = 8 | 2900 0008 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 36 | -32768 | 0 | 8000 0000 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 40 | <Ext Int16 Value TLV> | Length = 6 | 2900 0006 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 44 | 32767 | | 7FFF 0000 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 48 | |E| Type = 0x7204 | Length = 12 | 7204 000C +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 52 | | 0000 0000 + 4.9E-324 + 56 | | 0000 0001 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 60 | <END-OF-TLV 0xDFFF> | LENGTH = 4 | 0000 0004 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
It would generate the following TLVParseListener
event sequence:
listener.startParsing(); listener.complexTLVStart(0xDFFF, 0); listener.simpleTLV(0x2CFF, 8, new byte[][] {{ 0x10, 0x00, 0x00, 0x01 }}); listener.simpleTLV(0xA602, 5, new boolean[] { true }); listener.complexTLVStart(0x1F00, 28); listener.simpleTLV(0x21FF, 7, "áb"); listener.simpleTLV(0x2900, 8, new short[] { -32768, 0 }); listener.simpleTLV(0x2900, 6, new short[] { 32767 }); listener.complexTLVEnd(0x1F00, 28); listener.simpleTLV(0x7204, 12, new double[] { 4.9E-324 }); listener.complexTLVEnd(0x1FFF, 64); listener.endParsing(64);
TLVParseListener
,
TLV
Constructor Summary | |
TLVParser(byte[] buffer)
Create a TLVParser to parse the specified
buffer. |
|
TLVParser(byte[] buffer,
int offset,
int length)
Create a TLVParser to parse the specified
part of the buffer. |
|
TLVParser(InputStream is)
Create a TLVParser to parse the specified
InputStream . |
Method Summary | |
TLVParseListener |
getListener()
Returns the listener that is processing the XBE32 parsing events. |
int |
getOffset()
Returns the number of bytes that have been parsed. |
void |
parse()
Parse the full XBE32-encoded stream. |
void |
parseTLV()
Parse the next TLV from the XBE32-encoded stream. |
void |
setListener(TLVParseListener lis)
Sets the listener that would process XBE32 parsing events. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public TLVParser(InputStream is)
TLVParser
to parse the specified
InputStream
.
is
- The XBE32-encoded stream to be parsedpublic TLVParser(byte[] buffer)
TLVParser
to parse the specified
buffer.
buffer
- The XBE32-encoded buffer to be parsedpublic TLVParser(byte[] buffer, int offset, int length)
TLVParser
to parse the specified
part of the buffer.
buffer
- The XBE32-encoded buffer to be parsedoffset
- The buffer position to start parsing fromlength
- The number of bytes to be parsedMethod Detail |
public int getOffset()
public TLVParseListener getListener()
public void setListener(TLVParseListener lis)
lis
- the new parser listenerpublic void parse() throws IOException, TLVParseException
TLVParseListener
.
IOException
- if an error occurs while reading the underlying stream
TLVParseException
- if a syntax error occurs while parsing a XBE32
TLVs from the streamTLVParseListener
public void parseTLV() throws IOException, TLVParseException
TLVParseListener
.
If the parsed TLV is a Complex one, all its inner TLVs will be also parserd recursively, until the upper Complex TLV ends.
IOException
- if an error occurs while reading the underlying stream
TLVParseException
- if a syntax error occurs while parsing a XBE32
TLVs from the streamTLVParseListener
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |