READERNAME LogFormatter.java
From RifidiWiki
This class handles how the reader should display outgoing and incoming messages in the console logger in the IDE. If the reader does not need to display this information in any special way, it does not have to implement this class and instead can use either the GenericByteLogFormatter or the GenericStringLogFormatter. If it does need to implement this class, it should implement the LogFormatter interface.
formatMessage
This method needs to decode an incoming command into a command to be handled in the command formatter. It should put the command into a commandObject and put the commandObject in the first slot in an arraylist and return the arraylist.
public String formatMessage(byte[] rawMessage);
Arguments
- arg - The incoming or outgoing message that needs to be turned into a log message
Return Value
A string that will be printed in the console
Reference Implementation
This is the log formatter for the llrp reader. It displays both the bytes and the xml representation of the messages.
public String formatMessage(byte[] rawMessage) { ByteArrayInputStream is = new ByteArrayInputStream(rawMessage); String bytes = ByteAndHexConvertingUtility.toHexString(rawMessage); try { Message m = Message.receive(is); return "\nBYTES: \n" + bytes + "\nXML: \n" + m.toXMLString(); } catch (Exception e) { logger.error("Cannot serialize the message"); return "\nBytes: " + bytes; } }