|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectes.uc3m.it.xbe32.XBE32Parser
This class allows a XBE32-encoded stream or buffer to be parsed.
For each XBE32 Element parsed one or more parsing events are generated
and sent to the registered XBE32ParseListener
, if any.
This parser may employ a XBE32Dictionary
in order to translate
the TLV Type/id of the parsed XBE32 Element into a human-readable name.
For example, 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 | service | LENGTH = 76 | 0001 004C +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 4 | type | Length = 11 | 2102 000B +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 8 | 'p' | 'r' | 'i' | 'n' | 7072 696E +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 12 | 't' | 'e' | 'r' | | 7465 7200 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 16 | addr | Length = 8 | 2C03 0008 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 20 | 0xA9FE558B | A9FE 558B +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 24 | ports | Length = 8 | 2904 0008 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 28 | 515 | 631 | 0203 0277 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 32 |C|E| options | LENGTH = 44 | C005 002C +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 36 | |E| <EXT ATTRIBUTE TLV> | LENGTH = 20 | 5F00 0014 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 40 | <Ext Id TLV> | Length = 8 | 2CFF 0008 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 44 | 0x00000006 | 0000 0006 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 48 | <Ext Boolean Value TLV> | Length = 5 | 2600 0005 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 52 | false | | 0000 0000 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 56 |C| <EXT ATTRIBUTE TLV> | LENGTH = 20 | 9F00 0014 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 60 | <Ext Name TLV> | Length = 7 | 21FF 0007 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 64 | 'p' | 'p' | 'm' | | 7070 6D00 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 68 | <Ext Float32 Value TLV> | Length = 8 | 2E00 0008 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 72 | 20.5 | 41A4 0000 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
It would generate the following XBE32ParseListener
event sequence
(with the appropriate XBE32Dictionary
):
listener.startParsing(); listener.complexElementStart(false, 0x0001, "service", false, false); listener.attributeElement(false, 0x2102, "type", false, false, XBE32Element.STRING_VALUE_TYPE, "printer"); listener.attributeElement(false, 0x2C03, "addr", false, false, XBE32Element.OPAQUE4_VALUES_TYPE, new byte[][] {{ 0xA9, 0xFE, 0x55, 0x8B }}); listener.attributeElement(false, 0x2904, "ports", false, false, XBE32Element.INT16_VALUES_TYPE, new short[] { 515, 631 }); listener.complexElementStart(false, 0x0003, "options", true, true); listener.attributeElement(true, 0x000006, "color", false, true, XBE32Element.BOOLEAN_VALUES_TYPE, new boolean[] { false }); listener.attributeElement(true, 0, "ppm", true, false, XBE32Element.FLOAT32_VALUES_TYPE, new float[] { 20.5 }); listener.complexElementEnd(false, 0x0003, "options", true, true); listener.complexElementEnd(false, 0x0001, "service", false, false); listener.endParsing(76);
XBE32ParseListener
Constructor Summary | |
XBE32Parser(byte[] buffer)
Create a XBE32Parser to parse the specified
buffer. |
|
XBE32Parser(byte[] buffer,
int offset,
int length)
Create a XBE32Parser to parse the specified part of the
buffer. |
|
XBE32Parser(InputStream is)
Create a XBE32Parser to parse the specified
InputStream . |
Method Summary | |
XBE32Dictionary |
getDictionary()
Returns the dictionary employed to translate XBE32 Elements' ids into a human-readable name |
XBE32ParseListener |
getListener()
Returns the listener that is processing the XBE32 parsing events. |
void |
parse()
Parses the full XBE32-encoded stream. |
void |
parseElement()
Parses the next XBE32 Element from the stream. |
void |
setDictionary(XBE32Dictionary dict)
Sets the dictionary to be employed to translate XBE32 Elements' id into a human-readable name |
void |
setListener(XBE32ParseListener 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 XBE32Parser(InputStream is)
XBE32Parser
to parse the specified
InputStream
.
is
- The XBE32-encoded stream to be parsedpublic XBE32Parser(byte[] buffer)
XBE32Parser
to parse the specified
buffer.
buffer
- The XBE32-encoded buffer to be parsedpublic XBE32Parser(byte[] buffer, int offset, int length)
XBE32Parser
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 XBE32ParseListener getListener()
public void setListener(XBE32ParseListener lis)
lis
- the new parser listenerpublic XBE32Dictionary getDictionary()
public void setDictionary(XBE32Dictionary dict)
dict
- the new dictionarypublic void parse() throws IOException, XBE32ParseException
XBE32ParseListener
.
IOException
- when an error occurs reading the underlying stream
XBE32ParseException
- if a syntax error occurs while parsing the
XBE32 Elements from the streamXBE32ParseListener
public void parseElement() throws IOException, XBE32ParseException
XBE32ParseListener
.
IOException
- when an error occurs reading the underlying stream
XBE32ParseException
- if a syntax error occurs while parsing the
XBE32 Elements from the streamXBE32ParseListener
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |