Search in sources :

Example 1 with HierarchicalStreamCopier

use of com.thoughtworks.xstream.io.copy.HierarchicalStreamCopier in project ddf by codice.

the class GmlGeometryConverter method marshal.

@Override
public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) {
    Geometry geometry = (Geometry) value;
    GMLWriter gmlWriter = new GMLWriter();
    String gmlXml = gmlWriter.write(geometry);
    // Copy the GML XML into the writer
    XmlPullParser parser = null;
    try {
        parser = XppFactory.createDefaultParser();
        new HierarchicalStreamCopier().copy(new XppReader(new StringReader(gmlXml), parser), writer);
    } catch (XmlPullParserException e) {
        LOGGER.debug(ERROR_SERIALIZING_MSG, e);
    }
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) GMLWriter(com.vividsolutions.jts.io.gml2.GMLWriter) XppReader(com.thoughtworks.xstream.io.xml.XppReader) XmlPullParser(org.xmlpull.v1.XmlPullParser) StringReader(java.io.StringReader) HierarchicalStreamCopier(com.thoughtworks.xstream.io.copy.HierarchicalStreamCopier) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 2 with HierarchicalStreamCopier

use of com.thoughtworks.xstream.io.copy.HierarchicalStreamCopier in project ddf by codice.

the class CswTransformProvider method writeXml.

private void writeXml(BinaryContent content, HierarchicalStreamWriter writer) {
    try {
        XmlPullParser parser = XppFactory.createDefaultParser();
        new HierarchicalStreamCopier().copy(new XppReader(new InputStreamReader(content.getInputStream(), StandardCharsets.UTF_8), parser), writer);
    } catch (XmlPullParserException e) {
        throw new ConversionException("Unable to copy metadata to XML Output.", e);
    }
}
Also used : ConversionException(com.thoughtworks.xstream.converters.ConversionException) InputStreamReader(java.io.InputStreamReader) XppReader(com.thoughtworks.xstream.io.xml.XppReader) XmlPullParser(org.xmlpull.v1.XmlPullParser) HierarchicalStreamCopier(com.thoughtworks.xstream.io.copy.HierarchicalStreamCopier) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 3 with HierarchicalStreamCopier

use of com.thoughtworks.xstream.io.copy.HierarchicalStreamCopier in project ddf by codice.

the class MetacardMarshallerImpl method geoToXml.

private String geoToXml(BinaryContent content, XmlPullParser parser) throws UnsupportedEncodingException {
    PrintWriter destination;
    try (InputStreamReader inputStreamReader = new InputStreamReader(content.getInputStream(), StandardCharsets.UTF_8.name())) {
        XppReader source = new XppReader(inputStreamReader, parser);
        // if multi-threading, cannot abstract PrintWriter to class member
        destination = writerProvider.build(Metacard.class);
        new HierarchicalStreamCopier().copy(source, destination);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return destination.makeString();
}
Also used : Metacard(ddf.catalog.data.Metacard) InputStreamReader(java.io.InputStreamReader) XppReader(com.thoughtworks.xstream.io.xml.XppReader) HierarchicalStreamCopier(com.thoughtworks.xstream.io.copy.HierarchicalStreamCopier) IOException(java.io.IOException) PrintWriter(ddf.catalog.transformer.api.PrintWriter)

Aggregations

HierarchicalStreamCopier (com.thoughtworks.xstream.io.copy.HierarchicalStreamCopier)3 XppReader (com.thoughtworks.xstream.io.xml.XppReader)3 InputStreamReader (java.io.InputStreamReader)2 XmlPullParser (org.xmlpull.v1.XmlPullParser)2 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)2 ConversionException (com.thoughtworks.xstream.converters.ConversionException)1 Geometry (com.vividsolutions.jts.geom.Geometry)1 GMLWriter (com.vividsolutions.jts.io.gml2.GMLWriter)1 Metacard (ddf.catalog.data.Metacard)1 PrintWriter (ddf.catalog.transformer.api.PrintWriter)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1