Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

import java.io.OutputStream;

public class Main {
    public static <T> void writeXml(Class<T> _class, T jaxbElement, OutputStream outputStream, String encoding)
            throws JAXBException {
        JAXBContext context = JAXBContext.newInstance(_class);
        Marshaller marshaller = context.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.setProperty(Marshaller.JAXB_ENCODING, encoding);

        marshaller.marshal(jaxbElement, outputStream);
    }

    public static <T> void writeXml(Class<T> _class, T jaxbElement, OutputStream outputStream)
            throws JAXBException {
        writeXml(_class, jaxbElement, outputStream, "UTF-8");
    }
}