/** * */ package org.gcube.data.analysis.dminvocation; import java.io.ByteArrayOutputStream; import java.io.InputStream; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; import javax.xml.bind.Unmarshaller; import org.gcube.data.analysis.dminvocation.model.DataMinerInvocation; /** * The Class DataMinerInvocationManager. * * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) * Dec 4, 2018 */ public class DataMinerInvocationManager { /** * Marshaling. * * @param dmInvocation the dm invocation * @return the byte array output stream * @throws JAXBException the JAXB exception */ public static ByteArrayOutputStream marshaling(DataMinerInvocation dmInvocation) throws JAXBException { JAXBContext jaxbContext = JAXBContext.newInstance(DataMinerInvocation.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); ByteArrayOutputStream baos = new ByteArrayOutputStream(); jaxbMarshaller.marshal(dmInvocation, baos); return baos; } /** * Unmarshaling. * * @param dmInvocationXMLStream the dm invocation xml file * @return the data miner invocation * @throws JAXBException the JAXB exception */ public static DataMinerInvocation unmarshaling(InputStream dmInvocationXMLStream) throws JAXBException { //unMarshalingCategories(); JAXBContext jaxbContext = JAXBContext.newInstance(DataMinerInvocation.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); //We had written this file in marshalling example return (DataMinerInvocation) jaxbUnmarshaller.unmarshal(dmInvocationXMLStream); } }