Example usage for javax.xml.stream XMLStreamWriter writeStartElement

List of usage examples for javax.xml.stream XMLStreamWriter writeStartElement

Introduction

In this page you can find the example usage for javax.xml.stream XMLStreamWriter writeStartElement.

Prototype

public void writeStartElement(String localName) throws XMLStreamException;

Source Link

Document

Writes a start tag to the output.

Usage

From source file:net.solarnetwork.util.JavaBeanXmlSerializer.java

private void outputMap(Map<?, ?> map, String name, XMLStreamWriter out) throws XMLStreamException {
    writeElement(name, null, out, false);

    // for each entry, write an <entry> element
    for (Map.Entry<?, ?> me : map.entrySet()) {
        String entryName = me.getKey().toString();
        out.writeStartElement("entry");
        out.writeAttribute("key", entryName);

        Object value = me.getValue();
        if (value instanceof Collection) {
            // special collection case, we don't add nested element
            for (Object o : (Collection<?>) value) {
                outputObject(o, "value", out);
            }/*  ww w .j  av a 2s.c om*/
        } else {
            outputObject(value, null, out);
        }
        out.writeEndElement();
    }

    out.writeEndElement();
}

From source file:com.norconex.committer.idol.IdolCommitter.java

@Override
protected void saveToXML(XMLStreamWriter writer) throws XMLStreamException {
    writer.writeStartElement("host");
    writer.writeCharacters(getHost());//from   w  w w .  j a  v a 2 s.c  om
    writer.writeEndElement();

    writer.writeStartElement("cfsPort");
    writer.writeCharacters(Integer.toString(getCfsPort()));
    writer.writeEndElement();

    writer.writeStartElement("indexPort");
    writer.writeCharacters(Integer.toString(getIndexPort()));
    writer.writeEndElement();

    writer.writeStartElement("databaseName");
    writer.writeCharacters(getDatabaseName());
    writer.writeEndElement();

    writer.writeStartElement("dreAddDataParams");
    for (String key : dreAddDataParams.keySet()) {
        writer.writeStartElement("param");
        writer.writeAttribute(key, key);
        writer.writeCharacters(dreAddDataParams.get(key));
        writer.writeEndElement();
    }
    writer.writeEndElement();

    writer.writeStartElement("dreDeleteRefParams");
    for (String key : dreDeleteRefParams.keySet()) {
        writer.writeStartElement("param");
        writer.writeAttribute(key, key);
        writer.writeCharacters(dreDeleteRefParams.get(key));
        writer.writeEndElement();
    }
    writer.writeEndElement();
}

From source file:jp.co.atware.solr.geta.GETAssocComponent.java

/**
 * /*from  w ww . j  a va2  s. co m*/
 * @param xml
 * @param params
 * @param queryValue
 * @param queryType
 * @throws XMLStreamException
 */
protected void convReqWriteQuery(XMLStreamWriter xml, SolrParams params, String queryValue, QueryType queryType)
        throws XMLStreamException {

    if (queryType == QueryType.fulltext) {
        // freetext
        xml.writeStartElement("freetext");
        String stemmer = params.get(PARAM_STEMMER, config.defaults.stemmer);
        if (stemmer != null) {
            xml.writeAttribute("stemmer", stemmer);
        }
        String freetext_cutoff_df = params.get(PARAM_FREETEXT_CUTOFF_DF, config.defaults.freetext_cutoff_df);
        if (config.defaults.source != null) {
            xml.writeAttribute("cutoff-df", freetext_cutoff_df);
        }
        xml.writeCData(queryValue);
        xml.writeEndElement();
    } else {
        // article
        xml.writeStartElement("article");
        if (queryType == QueryType.vector) {
            xml.writeAttribute("vec", queryValue);
        } else {
            xml.writeAttribute("name", queryValue);
        }
        String source = params.get(PARAM_SOURCE, config.defaults.source);
        if (source != null) {
            xml.writeAttribute("source", source);
        }
        String article_cutoff_df = params.get(PARAM_ARTICLE_CUTOFF_DF, config.defaults.article_cutoff_df);
        if (source != null) {
            xml.writeAttribute("cutoff-df", article_cutoff_df);
        }
        xml.writeEndElement();
    }
}

From source file:com.fiorano.openesb.application.aps.OutPortInst.java

public void toJXMLString(XMLStreamWriter writer) throws XMLStreamException {

    //Start OutPortInst
    writer.writeStartElement("OutPortInst");

    writer.writeAttribute("isSyncRequestType", "" + isSyncRequestType());

    FioranoStackSerializer.writeElement("Name", m_strPortName, writer);

    if (!StringUtils.isEmpty(m_strDscription)) {
        FioranoStackSerializer.writeElement("Description", m_strDscription, writer);
    }/*from   w  w  w  . j a v  a2 s .  c o  m*/

    boolean standardXSD = false;

    if ("ON_EXCEPTION".equals(m_strPortName))
        standardXSD = CommonSchemas.ERROR_XSD == null ? m_strXSD == null
                : m_strXSD != null && CommonSchemas.ERROR_XSD.equals(m_strXSD);

    if (standardXSD) {
        writer.writeStartElement("StandardXSD");

        writer.writeEndElement();
    } else if (m_strXSDRef != null) {
        FioranoStackSerializer.writeElement(PortInstConstants.PORT_XSDREF, m_strXSDRef, writer);

    }

    if (m_strContextXSL != null) {
        writer.writeStartElement("SetContextXSL");
        writer.writeCData(m_strContextXSL);
        writer.writeEndElement();
    }

    if (m_strContextInfo != null) {
        writer.writeStartElement("SetContextInfo");
        writer.writeCData(m_strContextInfo);
        writer.writeEndElement();
    }

    if (m_transformerType != null) {
        writer.writeStartElement("SetTransformationType");
        writer.writeCData(m_transformerType);
        writer.writeEndElement();

    }

    if (!StringUtils.isEmpty(m_strJavaClass)) {
        FioranoStackSerializer.writeElement("JavaClass", m_strJavaClass, writer);
    }

    if (m_params != null && m_params.size() > 0) {
        Enumeration enums = m_params.elements();

        while (enums.hasMoreElements()) {
            Param param = (Param) enums.nextElement();
            if (!StringUtils.isEmpty(param.getParamName()) && !StringUtils.isEmpty(param.getParamValue())) {
                if (!checkIfDefaultValue(param.getParamName(), param.getParamValue())) {
                    param.toJXMLString(writer);
                }
            }
        }
    }
    //End OutPortInst
    writer.writeEndElement();

}

From source file:com.norconex.committer.idol.IdolCommitter.java

/**
 * Commits the addition operations./*  www . jav a2 s.co m*/
 * @param addOperations additions
 */
public void dreAddData(List<IAddOperation> addOperations) {
    if (addOperations.isEmpty()) {
        return;
    }
    if (LOG.isInfoEnabled()) {
        LOG.info("Sending " + addOperations.size() + " documents for addition to " + createURL());
    }

    StringBuilder b = new StringBuilder();
    b.append(createURL());

    if (isCFS()) {
        b.append("action=ingest&adds=");
        StringWriter xml = new StringWriter();
        XMLOutputFactory factory = XMLOutputFactory.newInstance();
        try {
            XMLStreamWriter writer = factory.createXMLStreamWriter(xml);
            writer.writeStartElement("adds");
            buildCfsXmlBatchContent(writer, addOperations);
            writer.writeEndElement();
            writer.flush();
            writer.close();
            b.append(URLEncoder.encode(xml.toString(), CharEncoding.UTF_8));
        } catch (Exception e) {
            throw new CommitterException("Cannot create XML.", e);
        }
        postToIDOL(b.toString(), StringUtils.EMPTY);
    } else {
        b.append("DREADDDATA?");
        QueryString qs = new QueryString();
        for (String key : dreAddDataParams.keySet()) {
            qs.addString(key, dreAddDataParams.get(key));
        }
        String addURL = qs.applyOnURL(b.toString());
        String idxBatch = buildIdxBatchContent(addOperations);
        postToIDOL(addURL, idxBatch);
    }
    if (LOG.isInfoEnabled()) {
        LOG.debug("Done sending additions to " + createURL());
    }
}

From source file:edu.stanford.cfuller.colocalization3d.correction.Correction.java

protected String writeToXML() {

    StringWriter sw = new StringWriter();

    try {//w  ww  .j  av a2 s  .  c  o  m

        XMLStreamWriter xsw = XMLOutputFactory.newFactory().createXMLStreamWriter(sw);

        xsw.writeStartDocument();
        xsw.writeCharacters("\n");
        xsw.writeStartElement("root");
        xsw.writeCharacters("\n");
        xsw.writeStartElement(CORRECTION_ELEMENT);
        xsw.writeAttribute(N_POINTS_ATTR, Integer.toString(this.distanceCutoffs.getDimension()));
        xsw.writeAttribute(REF_CHANNEL_ATTR, Integer.toString(this.referenceChannel));
        xsw.writeAttribute(CORR_CHANNEL_ATTR, Integer.toString(this.correctionChannel));

        xsw.writeCharacters("\n");

        for (int i = 0; i < this.distanceCutoffs.getDimension(); i++) {
            xsw.writeStartElement(CORRECTION_POINT_ELEMENT);

            xsw.writeAttribute(X_POS_ATTR, Double.toString(this.positionsForCorrection.getEntry(i, 0)));
            xsw.writeAttribute(Y_POS_ATTR, Double.toString(this.positionsForCorrection.getEntry(i, 1)));
            xsw.writeAttribute(Z_POS_ATTR, Double.toString(this.positionsForCorrection.getEntry(i, 2)));

            xsw.writeCharacters("\n");

            String x_param_string = "";
            String y_param_string = "";
            String z_param_string = "";

            for (int j = 0; j < this.correctionX.getColumnDimension(); j++) {
                String commaString = "";
                if (j != 0)
                    commaString = ", ";
                x_param_string += commaString + this.correctionX.getEntry(i, j);
                y_param_string += commaString + this.correctionY.getEntry(i, j);
                z_param_string += commaString + this.correctionZ.getEntry(i, j);
            }

            x_param_string = x_param_string.trim() + "\n";
            y_param_string = y_param_string.trim() + "\n";
            z_param_string = z_param_string.trim() + "\n";

            xsw.writeStartElement(X_PARAM_ELEMENT);

            xsw.writeCharacters(x_param_string);

            xsw.writeEndElement();

            xsw.writeCharacters("\n");

            xsw.writeStartElement(Y_PARAM_ELEMENT);

            xsw.writeCharacters(y_param_string);

            xsw.writeEndElement();

            xsw.writeCharacters("\n");

            xsw.writeStartElement(Z_PARAM_ELEMENT);

            xsw.writeCharacters(z_param_string);

            xsw.writeEndElement();

            xsw.writeCharacters("\n");

            xsw.writeEndElement();

            xsw.writeCharacters("\n");

        }

        xsw.writeStartElement(BINARY_DATA_ELEMENT);

        xsw.writeAttribute(ENCODING_ATTR, ENCODING_NAME);

        ByteArrayOutputStream bytesOutput = new ByteArrayOutputStream();

        try {

            ObjectOutputStream oos = new ObjectOutputStream(bytesOutput);

            oos.writeObject(this);

        } catch (java.io.IOException e) {
            java.util.logging.Logger.getLogger(LOG_NAME)
                    .severe("Exception encountered while serializing correction: " + e.getMessage());

        }

        HexBinaryAdapter adapter = new HexBinaryAdapter();
        xsw.writeCharacters(adapter.marshal(bytesOutput.toByteArray()));

        xsw.writeEndElement();

        xsw.writeCharacters("\n");

        xsw.writeEndElement();

        xsw.writeCharacters("\n");

        xsw.writeEndElement();

        xsw.writeCharacters("\n");

        xsw.writeEndDocument();

    } catch (XMLStreamException e) {

        java.util.logging.Logger.getLogger(LOG_NAME)
                .severe("Exception encountered while writing XML correction output: " + e.getMessage());

    }

    return sw.toString();

}

From source file:org.sfs.nodes.compute.container.GetContainer.java

@Override
public void handle(final SfsRequest httpServerRequest) {

    VertxContext<Server> vertxContext = httpServerRequest.vertxContext();
    aVoid().flatMap(new Authenticate(httpServerRequest))
            .flatMap(new ValidateActionAuthenticated(httpServerRequest))
            .map(aVoid -> fromSfsRequest(httpServerRequest)).map(new ValidateContainerPath())
            .flatMap(new LoadAccountAndContainer(vertxContext))
            .flatMap(new ValidateActionContainerListObjects(httpServerRequest)).flatMap(persistentContainer -> {

                HttpServerResponse httpServerResponse = httpServerRequest.response();

                MultiMap queryParams = httpServerRequest.params();
                MultiMap headerParams = httpServerRequest.headers();

                String format = queryParams.get(FORMAT);
                String accept = headerParams.get(ACCEPT);

                MediaType parsedAccept = null;

                if (equalsIgnoreCase("xml", format)) {
                    parsedAccept = APPLICATION_XML_UTF_8;
                } else if (equalsIgnoreCase("json", format)) {
                    parsedAccept = JSON_UTF_8;
                }//from  ww  w  .j ava 2 s.  c  om

                if (parsedAccept == null) {
                    if (!isNullOrEmpty(accept)) {
                        parsedAccept = parse(accept);
                    }
                }

                if (parsedAccept == null || (!PLAIN_TEXT_UTF_8.is(parsedAccept)
                        && !APPLICATION_XML_UTF_8.is(parsedAccept) && !JSON_UTF_8.equals(parsedAccept))) {
                    parsedAccept = PLAIN_TEXT_UTF_8;
                }

                Observable<Optional<ContainerStats>> oContainerStats;
                boolean hasPrefix = !Strings.isNullOrEmpty(queryParams.get(SfsHttpQueryParams.PREFIX));
                if (hasPrefix) {
                    oContainerStats = just(persistentContainer)
                            .flatMap(new LoadContainerStats(httpServerRequest.vertxContext()))
                            .map(Optional::of);
                } else {
                    oContainerStats = Defer.just(Optional.<ContainerStats>absent());
                }

                Observable<ObjectList> oObjectListing = just(persistentContainer)
                        .flatMap(new ListObjects(httpServerRequest));

                MediaType finalParsedAccept = parsedAccept;
                return combineSinglesDelayError(oContainerStats, oObjectListing,
                        (containerStats, objectList) -> {

                            if (containerStats.isPresent()) {

                                Metadata metadata = persistentContainer.getMetadata();

                                for (String key : metadata.keySet()) {
                                    SortedSet<String> values = metadata.get(key);
                                    if (values != null && !values.isEmpty()) {
                                        httpServerResponse.putHeader(
                                                format("%s%s", X_ADD_CONTAINER_META_PREFIX, key), values);
                                    }
                                }

                                httpServerResponse.putHeader(X_CONTAINER_OBJECT_COUNT,
                                        valueOf(containerStats.get().getObjectCount()));
                                httpServerResponse.putHeader(X_CONTAINER_BYTES_USED,
                                        BigDecimal.valueOf(containerStats.get().getBytesUsed())
                                                .setScale(0, ROUND_HALF_UP).toString());
                            }

                            BufferOutputStream bufferOutputStream = new BufferOutputStream();

                            if (JSON_UTF_8.is(finalParsedAccept)) {

                                try {
                                    JsonFactory jsonFactory = vertxContext.verticle().jsonFactory();
                                    JsonGenerator jg = jsonFactory.createGenerator(bufferOutputStream, UTF8);
                                    jg.writeStartArray();

                                    for (ListedObject listedObject : ordered(objectList.getObjects())) {

                                        jg.writeStartObject();
                                        jg.writeStringField("hash",
                                                base16().lowerCase().encode(listedObject.getEtag()));
                                        jg.writeStringField("last_modified",
                                                toDateTimeString(listedObject.getLastModified()));
                                        jg.writeNumberField("bytes", listedObject.getLength());
                                        jg.writeStringField("content_type", listedObject.getContentType());
                                        jg.writeStringField("name", listedObject.getName());
                                        jg.writeEndObject();
                                    }

                                    jg.writeEndArray();
                                    jg.close();
                                } catch (IOException e) {
                                    throw new RuntimeException(e);
                                }

                            } else if (APPLICATION_XML_UTF_8.is(finalParsedAccept)) {

                                String charset = UTF_8.toString();
                                XMLStreamWriter writer = null;
                                try {
                                    writer = newFactory().createXMLStreamWriter(bufferOutputStream, charset);

                                    writer.writeStartDocument(charset, "1.0");

                                    writer.writeStartElement("container");

                                    writer.writeAttribute("name",
                                            fromPaths(persistentContainer.getId()).containerName().get());

                                    for (ListedObject listedObject : ordered(objectList.getObjects())) {

                                        writer.writeStartElement("object");

                                        writer.writeStartElement("name");
                                        writer.writeCharacters(listedObject.getName());
                                        writer.writeEndElement();

                                        writer.writeStartElement("hash");
                                        writer.writeCharacters(
                                                base16().lowerCase().encode(listedObject.getEtag()));
                                        writer.writeEndElement();

                                        writer.writeStartElement("bytes");
                                        writer.writeCharacters(valueOf(listedObject.getLength()));
                                        writer.writeEndElement();

                                        writer.writeStartElement("content_type");
                                        writer.writeCharacters(listedObject.getContentType());
                                        writer.writeEndElement();

                                        writer.writeStartElement("last_modified");
                                        writer.writeCharacters(
                                                toDateTimeString(listedObject.getLastModified()));
                                        writer.writeEndElement();

                                        writer.writeEndElement();
                                    }

                                    writer.writeEndElement();

                                    writer.writeEndDocument();

                                } catch (XMLStreamException e) {
                                    throw new RuntimeException(e);
                                } finally {
                                    try {
                                        if (writer != null) {
                                            writer.close();
                                        }
                                    } catch (XMLStreamException e) {
                                        LOGGER.warn(e.getLocalizedMessage(), e);
                                    }
                                }

                            } else {
                                String charset = UTF_8.toString();
                                try (OutputStreamWriter outputStreamWriter = new OutputStreamWriter(
                                        bufferOutputStream, charset)) {
                                    for (ListedObject listedObject : ordered(objectList.getObjects())) {
                                        outputStreamWriter.write(listedObject.getName());
                                        outputStreamWriter.write("\n");
                                    }
                                } catch (IOException e) {
                                    throw new RuntimeException(e);
                                }
                            }
                            objectList.clear();
                            return bufferOutputStream;
                        }).flatMap(bufferOutputStream -> {
                            Buffer buffer = bufferOutputStream.toBuffer();
                            httpServerResponse.putHeader(HttpHeaders.CONTENT_TYPE, finalParsedAccept.toString())
                                    .putHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(buffer.length()));
                            return AsyncIO.append(buffer, httpServerRequest.response());
                        });
            }).single().subscribe(new ConnectionCloseTerminus<Void>(httpServerRequest) {
                @Override
                public void onNext(Void aVoid) {

                }
            }

    );

}

From source file:com.norconex.committer.idol.IdolCommitter.java

protected void buildCfsXmlDocument(XMLStreamWriter writer, InputStream is, Properties properties)
        throws XMLStreamException, IOException {
    try {//from  w w w  .  j a va 2 s . c  o m
        writer.writeStartElement("add");
        writer.writeStartElement("document");

        // Create a database key for the idol XML document
        String targetIdField = getTargetReferenceField();
        if (DEFAULT_IDOL_REFERENCE_FIELD.equalsIgnoreCase(targetIdField)) {
            writer.writeStartElement("reference");
            writer.writeCharacters(properties.getString(targetIdField));
            writer.writeEndElement();
        } else {
            writer.writeStartElement("metadata");
            writer.writeAttribute("name", targetIdField);
            writer.writeAttribute("value", properties.getString(targetIdField));
            writer.writeEndElement();
        }

        // Loop thru the list of properties and create XML fields
        // accordingly.
        for (Entry<String, List<String>> entry : properties.entrySet()) {
            if (!EqualsUtil.equalsAny(entry.getKey(), getTargetReferenceField(), getTargetContentField())) {
                for (String value : entry.getValue()) {
                    writer.writeStartElement("metadata");
                    writer.writeAttribute("name", entry.getKey());
                    writer.writeAttribute("value", value);
                    writer.writeEndElement();
                }
            }
        }

        // Store content at specified location
        String targetCtntField = getTargetContentField();
        String targetCtntValue = properties.getString(targetCtntField);

        writer.writeEndElement();

        writer.writeStartElement("source");
        writer.writeAttribute("content",
                Base64.encodeBase64String(targetCtntValue.getBytes(CharEncoding.UTF_8)));
        writer.writeEndElement();

        writer.writeEndElement();
    } finally {
        IOUtils.closeQuietly(is);
    }
}

From source file:com.github.lindenb.jvarkit.tools.vcfcmp.VcfCompareCallers.java

private void watch(XMLStreamWriter out, VariantContext ctx0, VariantContext ctx1, Genotype g0, Genotype g1,
        String sampleName, Counter<Category> count, Category cat) throws XMLStreamException {
    long n = count.incr(cat);
    if (out == null || n > super.numberOfExampleVariants)
        return;/*from  w w w  .ja v a2 s.  c o  m*/
    VariantContext variants[] = new VariantContext[] { ctx0, ctx1 };
    Genotype gts[] = new Genotype[] { g0, g1 };
    out.writeStartElement("diff");
    out.writeAttribute("type", cat.name());
    out.writeAttribute("sample", sampleName);
    for (int i = 0; i < 2; ++i) {
        if (variants[i] == null)
            continue;
        out.writeStartElement("variant");
        out.writeAttribute("file", String.valueOf(i + 1));
        out.writeAttribute("type", String.valueOf(variants[i].getType()));

        out.writeStartElement("chrom");
        out.writeCharacters(variants[i].getContig());
        out.writeEndElement();

        out.writeStartElement("pos");
        out.writeCharacters(String.valueOf(variants[i].getStart()));
        out.writeEndElement();

        out.writeStartElement("id");
        out.writeCharacters(variants[i].hasID() ? variants[i].getID() : ".");
        out.writeEndElement();

        out.writeStartElement("ref");
        out.writeCharacters(String.valueOf(variants[i].getReference()));
        out.writeEndElement();

        out.writeStartElement("alts");
        out.writeCharacters(String.valueOf(variants[i].getAlternateAlleles()));
        out.writeEndElement();

        if (gts[i] != null) {
            out.writeStartElement("genotype");
            out.writeAttribute("type", String.valueOf(gts[i].getType()));

            for (Allele a : gts[i].getAlleles()) {
                out.writeStartElement("allele");
                out.writeCharacters(a.toString());
                out.writeEndElement();
            }
            if (gts[i].hasDP()) {
                out.writeStartElement("dp");
                out.writeCharacters(String.valueOf(gts[i].getDP()));
                out.writeEndElement();
            }
            out.writeEndElement();
        }

        out.writeEndElement();
    }

    out.writeEndElement();
    out.writeCharacters("\n");
}

From source file:edu.stanford.cfuller.imageanalysistools.fitting.ImageObject.java

public void writeToXML(XMLStreamWriter xsw) {

    try {//from  w w  w .j  ava 2s .co m

        xsw.writeStartElement(OBJECT_ELEMENT);
        xsw.writeAttribute(LABEL_ATTR, Integer.toString(this.label));
        xsw.writeAttribute(IMAGE_ATTR, this.imageID);
        xsw.writeCharacters("\n");
        for (int i = 0; i < this.numberOfChannels; i++) {

            xsw.writeStartElement(CHANNEL_ELEMENT);
            xsw.writeAttribute(CH_ID_ATTR, Integer.toString(i));
            xsw.writeCharacters("\n");
            xsw.writeStartElement(FIT_ELEMENT);
            xsw.writeAttribute(R2_ATTR, Double.toString(this.getFitR2ByChannel().get(i)));
            xsw.writeAttribute(ERROR_ATTR, Double.toString(this.getFitErrorByChannel().get(i)));
            xsw.writeAttribute(N_PHOTONS_ATTR, Double.toString(this.getNPhotonsByChannel().get(i)));
            xsw.writeCharacters("\n");
            xsw.writeStartElement(PARAMETERS_ELEMENT);
            xsw.writeCharacters(this.getFitParametersByChannel().get(i).toString().replace(";", ",")
                    .replace("}", "").replace("{", ""));
            xsw.writeEndElement(); //parameters
            xsw.writeCharacters("\n");
            xsw.writeStartElement(POSITION_ELEMENT);
            xsw.writeCharacters(this.getPositionForChannel(i).toString().replace(";", ",").replace("}", "")
                    .replace("{", ""));
            xsw.writeEndElement(); //position
            xsw.writeCharacters("\n");
            xsw.writeEndElement(); //fit
            xsw.writeCharacters("\n");
            xsw.writeEndElement(); //channel
            xsw.writeCharacters("\n");
        }
        xsw.writeStartElement(SERIAL_ELEMENT);
        xsw.writeAttribute(ENCODING_ATTR, ENCODING_NAME);

        ByteArrayOutputStream bytesOutput = new ByteArrayOutputStream();

        try {

            ObjectOutputStream oos = new ObjectOutputStream(bytesOutput);

            oos.writeObject(this);

        } catch (java.io.IOException e) {
            LoggingUtilities.getLogger()
                    .severe("Exception encountered while serializing ImageObject: " + e.getMessage());

        }

        Base64BinaryAdapter adapter = new Base64BinaryAdapter();
        xsw.writeCharacters(adapter.marshal(bytesOutput.toByteArray()));

        xsw.writeEndElement(); //serial

        xsw.writeCharacters("\n");

        xsw.writeEndElement(); //object

        xsw.writeCharacters("\n");

    } catch (XMLStreamException e) {

        LoggingUtilities.getLogger()
                .severe("Exception encountered while writing XML correction output: " + e.getMessage());

    }

}