|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectes.uc3m.it.xbe32.tlv.TLVPrinter
This auxiliary TLVParseListener
class prints the fields of the TLVs
being parsed from an XBE32-encoded stream.
The TLVs are printed in the specified PrintStream
(or in System.out
by default).
For example, a XBE32-encoded stream that generates the following TLVParseListener
events when parsed by a TLVParser
:
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);
The TLVPrinter
would print the following text at the
specified PrintStream
:
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 allows a second TLVParseListener
to be registered. Thus it
is able to process the TLV parsing events once the TLVs are printed into the
specified output stream.
Finally, a XBE32Dictionary
could
be also set to translate the TLV's Type field into a human-readable name.
TLVParser.setListener()
,
TLV
Constructor Summary | |
TLVPrinter(TLVParser parser)
Creates a new TLVPrinter for the specified TLVParser |
Method Summary | |
void |
complexTLVEnd(int type,
int length)
This method is called when a Complex TLV has just been processed by the TLVParser . |
void |
complexTLVStart(int type,
int length)
This method is called when a Complex TLV is found by the TLVParser . |
void |
endParsing(int length)
This method is called when the TLVParser successfully ends
parsing the full XBE32-encoded stream. |
XBE32Dictionary |
getDictionary()
Returns the dictionary employed to translate TLV Types into a human-readable name |
TLVParseListener |
getListener()
Returns the registered TLVParseListener, if any |
PrintStream |
getPrintStream()
Returns the PrintStream where TLVs are printed in |
static void |
main(String[] args)
TLVPrinter can be executed as an standalone command-line application. |
void |
setDictionary(XBE32Dictionary dict)
Sets the dictionary to be employed to translate TLV Types into a human-readable name |
void |
setListener(TLVParseListener lis)
Sets the TLVParseListener that receives TLV parsing events |
void |
setPrintStream(PrintStream out)
Sets the PrintStream to write TLVs at |
void |
simpleTLV(int type,
int length,
Object value)
This method is called when a Simple TLV is processed by the TLVParser . |
void |
startParsing()
This method is called when the TLVParser.parse() method is
called and the parsing process starts. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public TLVPrinter(TLVParser parser)
parser
- the TLVParser to register atMethod Detail |
public TLVParseListener getListener()
public void setListener(TLVParseListener lis)
lis
- the TLVParseListener to registerpublic XBE32Dictionary getDictionary()
public void setDictionary(XBE32Dictionary dict)
dict
- the new dictionarypublic PrintStream getPrintStream()
public void setPrintStream(PrintStream out) throws IllegalArgumentException
out
- the PrintStream to use
IllegalArgumentException
- if out is null
public void startParsing()
TLVParseListener
TLVParser.parse()
method is
called and the parsing process starts.
startParsing
in interface TLVParseListener
TLVParser.parse()
public void complexTLVStart(int type, int length) throws TLVParseException
TLVParseListener
TLVParser
.
complexTLVStart
in interface TLVParseListener
type
- the Type field of the Complex TLV to be parsedlength
- the Length field of the Complex TLV to be parsed
TLVParseException
- the listener may throw this exception if any
syntax error occurs while processing this eventTLVParser.parse()
,
TLVParser.parseTLV()
public void complexTLVEnd(int type, int length) throws TLVParseException
TLVParseListener
TLVParser
.
complexTLVEnd
in interface TLVParseListener
type
- the Type field of the Complex TLV that has been parsedlength
- the Length field of the Complex TLV thas has been parsed
TLVParseException
- the listener may throw this exception if any
syntax error occurs while processing this eventTLVParser.parse()
,
TLVParser.parseTLV()
public void simpleTLV(int type, int length, Object value) throws TLVParseException
TLVParseListener
TLVParser
.
simpleTLV
in interface TLVParseListener
type
- the Type field of the Simple TLV being parsedlength
- the Length field of the Simple TLV being parsedvalue
- the Values field of the Simple TLV being parsed
TLVParseException
- the listener may throw this exception if any
syntax error occurs while processing this eventTLVParser.parse()
,
TLVParser.parseTLV()
public void endParsing(int length)
TLVParseListener
TLVParser
successfully ends
parsing the full XBE32-encoded stream.
endParsing
in interface TLVParseListener
TLVParser.parse()
public static void main(String[] args)
Usage: TLVPrinter <xbe32> [<dict>] <xbe32> : XBE32 encoded file to be printed (Use '-' to read from stdin). <dict> : Properties file with all the 'name=id' mappings.
args
- Command line parameters
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |