From: <sno...@us...> - 2013-09-12 17:16:05
|
Revision: 89 http://sourceforge.net/p/openrpg/svn/89 Author: snowdog_ Date: 2013-09-12 17:16:02 +0000 (Thu, 12 Sep 2013) Log Message: ----------- Added getAsString method to ORPGMessage to convert message to string to simplify debugging of message headers Modified Paths: -------------- trunk/src/openrpg2/common/core/ORPGMessage.java Modified: trunk/src/openrpg2/common/core/ORPGMessage.java =================================================================== --- trunk/src/openrpg2/common/core/ORPGMessage.java 2013-09-12 05:55:34 UTC (rev 88) +++ trunk/src/openrpg2/common/core/ORPGMessage.java 2013-09-12 17:16:02 UTC (rev 89) @@ -25,6 +25,8 @@ import java.util.Enumeration; import java.util.Hashtable; +import java.util.Iterator; +import java.util.Map; import openrpg2.common.core.network.HeaderEncoder; import openrpg2.common.core.network.NetworkMessage; import openrpg2.common.core.route.MessageAddress; @@ -115,7 +117,7 @@ * @return Identifier as String */ public String getHandlerId(){ - return new String(handlerId); + return handlerId; } /** @@ -169,7 +171,7 @@ * @return value associated with key as string */ public String getHeader(String key){ - String s = ""; + String s; if (! header.containsKey(key)){ return null; } @@ -243,4 +245,27 @@ public int[] getFinalRecipientList(){ return recipients; } + + /** + * Debugging only. Returns the header information (key value pairs) as a string and includes a + * byte count of data (if present). + * @return string representation of ORPGMessage + */ + public String getAsString(){ + StringBuilder s = new StringBuilder(); + Iterator it = this.header.entrySet().iterator(); + s.append("ORPGMessage: "); + while (it.hasNext()) { + Map.Entry pairs = (Map.Entry)it.next(); + s.append("("); + s.append(pairs.getKey()); + s.append(","); + s.append(pairs.getValue()); + s.append(") "); + } + s.append("[DATA: "); + if( this.data == null ){ s.append("NULL]"); } + else{ s.append(this.data.length); s.append(" BYTES"); } + return s.toString(); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |