Here you can find the source of marshal(Object obj, OutputStream out)
public static void marshal(Object obj, OutputStream out)
//package com.java2s; //License from project: Open Source License import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; import java.io.*; public class Main { public static void marshal(Object obj, OutputStream out) { try {//from www .j a v a 2 s .c om JAXBContext context = JAXBContext.newInstance(obj.getClass()); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(obj, out); } catch (JAXBException e) { throw new RuntimeException(e); } } public static void marshal(Object obj, Writer writer) { try { JAXBContext context = JAXBContext.newInstance(obj.getClass()); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(obj, writer); } catch (JAXBException e) { throw new RuntimeException(e); } } }