Search in sources :

Example 1 with InspireXmlStreamWriter

use of org.n52.svalbard.write.InspireXmlStreamWriter in project arctic-sea by 52North.

the class InspireXmlEncoder method encodeObject.

private XmlObject encodeObject(InspireObject objectToEncode, EncodingContext ctx) throws EncodingException {
    try {
        checkIfSupported(objectToEncode);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        EncodingContext context = ctx.with(EncoderFlags.ENCODER_REPOSITORY, getEncoderRepository()).with(XmlEncoderFlags.XML_OPTIONS, (Supplier<XmlOptions>) this::getXmlOptions);
        new InspireXmlStreamWriter(context, out, objectToEncode).write();
        String s = out.toString("UTF8");
        return XmlObject.Factory.parse(s);
    } catch (XMLStreamException | DateTimeFormatException | XmlException | UnsupportedEncodingException ex) {
        throw new EncodingException("Error encoding Inspire extended capabilities!", ex);
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) EncodingException(org.n52.svalbard.encode.exception.EncodingException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) XmlException(org.apache.xmlbeans.XmlException) InspireXmlStreamWriter(org.n52.svalbard.write.InspireXmlStreamWriter) DateTimeFormatException(org.n52.shetland.util.DateTimeFormatException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Supplier(java.util.function.Supplier) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Supplier (java.util.function.Supplier)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 XmlException (org.apache.xmlbeans.XmlException)1 DateTimeFormatException (org.n52.shetland.util.DateTimeFormatException)1 EncodingException (org.n52.svalbard.encode.exception.EncodingException)1 InspireXmlStreamWriter (org.n52.svalbard.write.InspireXmlStreamWriter)1