List of usage examples for org.dom4j.jaxb JAXBWriter JAXBWriter
public JAXBWriter(String contextPath)
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; }