serializableMarshaller.write(obj, out);
serialize(dos, obj);
   public void write(Object obj, OutputStream out) throws IOException   {                DataOutputStream dos;            if (out instanceof DataOutputStream)      {         dos = (DataOutputStream)out;      }      else      {         //TODO - We should get remoting to pass in a DataOutputStream         //So we don't have to wrap it every time         dos = new DataOutputStream(out);      }            handleVersion(obj, dos);      try      {                  if (obj instanceof InvocationRequest)         {            if (trace) { log.trace("writing InvocationRequest"); }               InvocationRequest req = (InvocationRequest)obj;               Object param;               if (req.getParameter() instanceof MessagingMarshallable)            {               param = ((MessagingMarshallable)req.getParameter()).getLoad();            }            else            {               param = req.getParameter();            }               if (trace) { log.trace("param is " + param); }               if (param instanceof MethodInvocation)            {               MethodInvocation mi = (MethodInvocation)param;                  String methodName = mi.getMethod().getName();                  if (trace) { log.trace("methodInvocation (" + methodName + "())"); }                  if (methodName.equals("send"))               {                  dos.writeByte(SEND);                     writeHeader(mi, dos);                     JBossMessage m = (JBossMessage)mi.getArguments()[0];                     dos.writeByte(m.getType());                     m.write(dos);                     dos.flush();                     if (trace) { log.trace("wrote send()"); }               }               else if ("more".equals(methodName))               {                  dos.writeByte(MORE);                     writeHeader(mi, dos);                     dos.flush();                     if (trace) { log.trace("wrote activate()"); }               }                          else if ("acknowledge".equals(methodName))               {                  dos.writeByte(ACKNOWLEDGE);                     writeHeader(mi, dos);                                    AckInfo ack = (AckInfo)mi.getArguments()[0];                                    ack.write(dos);                     dos.flush();                     if (trace) { log.trace("wrote acknowledge()"); }               }               else if ("acknowledgeBatch".equals(methodName))               {                  dos.writeByte(ACKNOWLEDGE_BATCH);                     writeHeader(mi, dos);                                    List acks = (List)mi.getArguments()[0];                     dos.writeInt(acks.size());                     Iterator iter = acks.iterator();                     while (iter.hasNext())                  {                     AckInfo ack = (AckInfo)iter.next();                     ack.write(dos);                  }                     dos.flush();                     if (trace) { log.trace("wrote acknowledge()"); }               }               else if ("sendTransaction".equals(methodName))               {                  dos.writeByte(SEND_TRANSACTION);                     writeHeader(mi, dos);                     TransactionRequest request = (TransactionRequest)mi.getArguments()[0];                     request.write(dos);                     dos.flush();                     if (trace) { log.trace("wrote getMessageNow()"); }               }               else if ("getIdBlock".equals(methodName))               {                  dos.writeByte(GET_ID_BLOCK);                     writeHeader(mi, dos);                     int size = ((Integer)mi.getArguments()[0]).intValue();                     dos.writeInt(size);                     dos.flush();                     if (trace) { log.trace("wrote getIdBlock()"); }               }                          else if ("cancelDeliveries".equals(methodName) && mi.getArguments() != null)               {                  dos.writeByte(CANCEL_DELIVERIES);                     writeHeader(mi, dos);                     List ids = (List)mi.getArguments()[0];                     dos.writeInt(ids.size());                     Iterator iter = ids.iterator();                     while (iter.hasNext())                  {                     AckInfo ack = (AckInfo)iter.next();                     ack.write(dos);                  }                     dos.flush();                     if (trace) { log.trace("wrote cancelDeliveries()"); }               }               else               {                  dos.write(SERIALIZED);                     // Delegate to serialization to handle the wire format                  serializableMarshaller.write(obj, dos);                     if (trace) { log.trace("wrote using standard serialization"); }               }            }            else if (param instanceof ClientDelivery)            {               //Message delivery callback                  if (trace) { log.trace("DeliveryRunnable"); }                  ClientDelivery dr = (ClientDelivery)param;                  dos.writeByte(CALLBACK);                  dr.write(dos);                  dos.flush();                  if (trace) { log.trace("wrote DeliveryRunnable"); }            }            else            {               //Internal invocation                  dos.write(SERIALIZED);                  //Delegate to serialization to handle the wire format               serializableMarshaller.write(obj, dos);                  if (trace) { log.trace("wrote using standard serialization"); }            }         }         else if (obj instanceof InvocationResponse)         {            if (trace) { log.trace("writing InvocationResponse"); }               InvocationResponse resp = (InvocationResponse)obj;               Object res;               if (resp.getResult() instanceof MessagingMarshallable)            {               res = ((MessagingMarshallable)resp.getResult()).getLoad();            }            else            {               res = resp.getResult();            }               if (trace) { log.trace("result is " + res); }               if (res == null && !resp.isException())            {                      dos.write(NULL_RESPONSE);                  dos.flush();                  if (trace) { log.trace("wrote null response"); }            }                     else if (res instanceof IdBlock)            {               //Return value from getMessageNow               dos.write(ID_BLOCK_RESPONSE);                  IdBlock block = (IdBlock)res;                  block.write(dos);                  dos.flush();                  if (trace) { log.trace("wrote id block response"); }            }            else if (res instanceof HandleMessageResponse)            {                        //Return value from delivering messages to client               dos.write(HANDLE_MESSAGE_RESPONSE);                  HandleMessageResponse response = (HandleMessageResponse)res;                  response.write(dos);                  dos.flush();                  if (trace) { log.trace("wrote handle message response"); }            }            else            {               dos.write(SERIALIZED);                  //Delegate to serialization to handle the wire format               serializableMarshaller.write(obj, out);                  if (trace) { log.trace("wrote using standard serialization"); }            }         }         else         {            throw new IllegalStateException("Invalid object " + obj);         }      }      catch (Exception e)      {         IOException e2 = new IOException(e.getMessage());         e2.setStackTrace(e.getStackTrace());         throw e2;      }   }