public static void write(Config config, OutputStream os) { ByteArrayOutputStream tempStream = new ByteArrayOutputStream(); JAXB.marshal(config, tempStream); try { os.write(XMLPrettyPrinter.prettyPrintXML(new String(tempStream.toByteArray())).getBytes()); } catch (IOException | TransformerException | XPathExpressionException | XPathFactoryConfigurationException | ParserConfigurationException | SAXException ex) { throw new RuntimeException("Could not format XML"); } }
/** * @param outputStream * The OutputStream to which the Trace should be written to * @param workflowTrace * The WorkflowTrace that should be written * @throws JAXBException * JAXBException if the JAXB reports a problem * @throws IOException * If something goes wrong while writing to the stream */ public static void write(OutputStream outputStream, WorkflowTrace workflowTrace) throws JAXBException, IOException { context = getJAXBContext(); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); try (ByteArrayOutputStream tempStream = new ByteArrayOutputStream()) { m.marshal(workflowTrace, tempStream); try { outputStream.write(XMLPrettyPrinter.prettyPrintXML(new String(tempStream.toByteArray())).getBytes()); } catch (TransformerException | XPathExpressionException | XPathFactoryConfigurationException | ParserConfigurationException | SAXException ex) { throw new RuntimeException("Could not format XML"); } } outputStream.close(); }