Example usage for org.dom4j.jaxb JAXBWriter JAXBWriter

List of usage examples for org.dom4j.jaxb JAXBWriter JAXBWriter

Introduction

In this page you can find the example usage for org.dom4j.jaxb JAXBWriter JAXBWriter.

Prototype

public JAXBWriter(String contextPath) 

Source Link

Document

Creates a new JAXBWriter for the given JAXB context path.

Usage

From source file:fr.cls.atoll.motu.library.misc.xml.XMLUtils.java

License:Open Source License

/**
 * Dom4j to intput stream./*from w ww  .  ja v a  2s.  co m*/
 * 
 * @param document the document
 * @param contextPath the context path
 * 
 * @return the input stream
 * 
 * @throws MotuExceptionBase the motu exception base
 */
public static InputStream dom4jToIntputStream(org.dom4j.Document document, String contextPath)
        throws MotuExceptionBase {
    ByteArrayInputStream byteArrayInputStream = null;
    try {
        Element root = document.getRootElement();
        JAXBWriter jaxbWriter = new JAXBWriter(contextPath);
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        jaxbWriter.setOutput(byteArrayOutputStream);

        jaxbWriter.startDocument();
        jaxbWriter.writeElement(root);
        jaxbWriter.endDocument();

        byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
    } catch (IOException e) {
        throw new MotuException("ERROR in XMLUtils#dom4jToIntputStream", e);
    } catch (SAXException e) {
        throw new MotuException("ERROR in XMLUtils#dom4jToIntputStream", e);
    }
    return byteArrayInputStream;

}