Here you can find the source of marshallMessage(Object message, Marshaller marshaller, DataOutputStream dos)
public static void marshallMessage(Object message, Marshaller marshaller, DataOutputStream dos) throws JAXBException, IOException
//package com.java2s; //License from project: Open Source License import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.IOException; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; public class Main { public static void marshallMessage(Object message, Marshaller marshaller, DataOutputStream dos) throws JAXBException, IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); marshaller.marshal(message, baos); byte[] buff = baos.toByteArray(); dos.writeInt(buff.length);// ww w . java 2 s. c o m dos.write(buff); dos.flush(); } }