Author: toad
Date: 2007-04-18 19:16:44 +0000 (Wed, 18 Apr 2007)
New Revision: 12791

Modified:
   trunk/freenet/src/freenet/io/comm/Message.java
Log:
Enable writing of sub-messages

Modified: trunk/freenet/src/freenet/io/comm/Message.java
===================================================================
--- trunk/freenet/src/freenet/io/comm/Message.java      2007-04-18 19:11:26 UTC 
(rev 12790)
+++ trunk/freenet/src/freenet/io/comm/Message.java      2007-04-18 19:16:44 UTC 
(rev 12791)
@@ -184,7 +184,7 @@
                _payload.put(key, value);
        }

-       public byte[] encodeToPacket(PeerContext destination) {
+       public byte[] encodeToPacket(PeerContext destination, boolean 
includeSubMessages, boolean isSubMessage) {
 //             if (this.getSpec() != MessageTypes.ping && this.getSpec() != 
MessageTypes.pong)
 //             Logger.logMinor("<<<<< Send message : " + this);

@@ -200,8 +200,21 @@
                        }
                        dos.flush();
                } catch (IOException e) {
-                       e.printStackTrace();
+                       throw new IllegalStateException(e);
                }
+               
+               if(_subMessages != null && includeSubMessages) {
+                       for(int i=0;i<_subMessages.size();i++) {
+                               byte[] temp = 
((Message)_subMessages.get(i)).encodeToPacket(destination, false, true);
+                               try {
+                                       dos.writeShort(temp.length);
+                                       dos.write(temp);
+                               } catch (IOException e) {
+                                       throw new IllegalStateException(e);
+                               }
+                       }
+               }
+               
                byte[] buf = baos.toByteArray();
        if(Logger.shouldLog(Logger.DEBUG, Message.class))
                Logger.minor(this, "Length: "+buf.length+", hash: 
"+Fields.hashCode(buf));


Reply via email to