Example usage for javax.xml.stream XMLStreamWriter flush

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

Introduction

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

Prototype

public void flush() throws XMLStreamException;

Source Link

Document

Write any cached data to the underlying output mechanism.

Usage

From source file:Main.java

public static void endElement(XMLStreamWriter writer) throws XMLStreamException {
    writer.writeEndElement();//from w w  w  .ja  va2s .  com
    writer.flush();
}

From source file:Main.java

/**
 * Borrowed from org.apache.xml.security.test.stax.utils.XmlReaderToWriter
 *//*from   w w w . ja  va 2s  . c  o  m*/
public static void writeAll(XMLStreamReader xmlr, XMLStreamWriter writer) throws XMLStreamException {
    while (xmlr.hasNext()) {
        xmlr.next();
        write(xmlr, writer);
    }
    writer.flush();
}

From source file:XmlReaderToWriter.java

public static void writeAll(XMLStreamReader xmlr, XMLStreamWriter writer) throws XMLStreamException {
    while (xmlr.hasNext()) {
        write(xmlr, writer);/*from  ww w.  j  a v a2 s . c o  m*/
        xmlr.next();
    }
    write(xmlr, writer); // write the last element
    writer.flush();
}

From source file:com.predic8.membrane.annot.bean.MCUtil.java

private static String defineBean(SerializationContext sc, Object object, String idSuggestion,
        boolean requireBeanId) throws XMLStreamException {
    if (sc.ids.containsKey(object))
        return sc.ids.get(object);

    String id = idSuggestion;//from   ww w.j a  v  a  2 s.co m

    if (requireBeanId && id == null)
        id = "bean" + sc.nextBean++;

    StringWriter sw = new StringWriter();
    XMLStreamWriter xew = xmlOutputFactory.createXMLStreamWriter(sw);

    addXML(object, id, xew, sc);
    xew.flush();

    if (id == null)
        id = "bean" + sc.nextBean++;

    sc.beans.put(id, sw.toString());
    sc.ids.put(object, id);

    return id;
}

From source file:eu.artist.postmigration.eubt.helpers.SOAPHelper.java

/**
 * @param migratedSoapEnvelope/*www. ja va  2 s .c  om*/
 * @return
 * @throws XMLStreamException
 * @throws FactoryConfigurationError
 * @throws IOException
 */
public static String storeSoapEnvelopeToFile(final SOAPEnvelope migratedSoapEnvelope,
        final String migratedResponseFileFolder) throws EUBTException {
    // store created soap envelope in a file
    final String migratedResponseFileLocation = migratedResponseFileFolder
            + migratedSoapEnvelope.getSOAPBodyFirstElementLocalName() + ".xml";
    XMLStreamWriter writer;
    try {
        writer = new IndentingXMLStreamWriter(XMLOutputFactory.newInstance()
                .createXMLStreamWriter(new FileWriter(migratedResponseFileLocation)));
        migratedSoapEnvelope.serialize(writer);
        writer.flush();
    } catch (XMLStreamException e) {
        throw new EUBTException(
                "Failed to create stream writer, or serialize or flush output. Detailed Exception: " + e);
    } catch (FactoryConfigurationError e) {
        throw new EUBTException("Failed to configure xml output factory. Detailed Exception: " + e);
    } catch (IOException e) {
        throw new EUBTException("General I/O Exception (wrong path, file location?). Detailed Exception: " + e);
    }
    return migratedResponseFileLocation;
}

From source file:com.microsoft.windowsazure.services.table.client.AtomPubParser.java

/**
 * Reserved for internal use. Writes a single entity to the specified <code>XMLStreamWriter</code> as a complete XML
 * document.//from w ww . j a  v a2 s  . c  o m
 * 
 * @param entity
 *            The instance implementing {@link TableEntity} to write to the output stream.
 * @param isTableEntry
 *            A flag indicating the entity is a reference to a table at the top level of the storage service when
 *            <code>true<code> and a reference to an entity within a table when <code>false</code>.
 * @param xmlw
 *            The <code>XMLStreamWriter</code> to write the entity to.
 * @param opContext
 *            An {@link OperationContext} object used to track the execution of the operation.
 * 
 * @throws XMLStreamException
 *             if an error occurs creating or accessing the stream.
 * @throws StorageException
 *             if a Storage service error occurs.
 */
protected static void writeSingleEntityToStream(final TableEntity entity, final boolean isTableEntry,
        final XMLStreamWriter xmlw, final OperationContext opContext)
        throws XMLStreamException, StorageException {
    // default is UTF8
    xmlw.writeStartDocument("UTF-8", "1.0");

    writeEntityToStream(entity, isTableEntry, xmlw, opContext);

    // end doc
    xmlw.writeEndDocument();
    xmlw.flush();
}

From source file:com.norconex.jefmon.model.ConfigurationDAO.java

public static void saveConfig(JEFMonConfig config) throws IOException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Saving JEF config to: " + CONFIG_FILE);
    }//  w ww.java 2 s.  c  o m

    if (!CONFIG_FILE.exists()) {
        File configDir = new File(FilenameUtils.getFullPath(CONFIG_FILE.getAbsolutePath()));
        if (!configDir.exists()) {
            LOG.debug("Creating JEF Monitor config directory for: " + CONFIG_FILE);
            configDir.mkdirs();
        }
    }

    OutputStream out = new FileOutputStream(CONFIG_FILE);
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    try {
        XMLStreamWriter xml = factory.createXMLStreamWriter(out);
        xml.writeStartDocument();
        xml.writeStartElement("jefmon-config");

        xml.writeStartElement("instance-name");
        xml.writeCharacters(config.getInstanceName());
        xml.writeEndElement();

        xml.writeStartElement("default-refresh-interval");
        xml.writeCharacters(Integer.toString(config.getDefaultRefreshInterval()));
        xml.writeEndElement();

        saveRemoteUrls(xml, config.getRemoteInstanceUrls());
        saveMonitoredPaths(xml, config.getMonitoredPaths());
        saveJobActions(xml, config.getJobActions());

        xml.writeEndElement();
        xml.writeEndDocument();
        xml.flush();
        xml.close();
    } catch (XMLStreamException e) {
        throw new IOException("Cannot save as XML.", e);
    }
    out.close();
}

From source file:gdv.xport.util.HtmlFormatter.java

private static void writeDetailsTo(final XMLStreamWriter xmlStreamWriter, final Satz satz, final int zeile)
        throws XMLStreamException {
    xmlStreamWriter.writeStartElement("h3");
    xmlStreamWriter/*from w  w w .j  a  v a  2s .  c  om*/
            .writeCharacters("Satzart " + satz.getSatzart() + " (" + satz.getClass().getSimpleName() + ")");
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
    int n = zeile;
    for (Iterator<Teildatensatz> iterator = satz.getTeildatensaetze().iterator(); iterator.hasNext();) {
        Teildatensatz teildatensatz = iterator.next();
        writeDetailsTo(xmlStreamWriter, teildatensatz, n);
        n++;
    }
    xmlStreamWriter.flush();
}

From source file:com.predic8.membrane.integration.ProxyRuleTest.java

@Test
public void testWriteRuleToByteBuffer() throws Exception {
    rule1 = new ProxyRule(new ProxyRuleKey(8888));
    rule1.setName("Rule 1");
    rule1.setInboundTLS(true);/*from  ww  w. j av a 2 s . c  om*/
    rule1.setBlockResponse(true);
    rule1.setInterceptors(getInterceptors());

    ByteArrayOutputStream os = new ByteArrayOutputStream();
    XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(os, Constants.UTF_8);
    rule1.write(writer);
    writer.flush();
    buffer = os.toByteArray();
}

From source file:diuf.unifr.ch.first.xwot.rxtx.notifications.JAXBEntity.java

@Override
public void writeTo(final OutputStream outstream) throws IOException {
    XMLOutputFactory xmloutputf = XMLOutputFactory.newInstance();
    try {/*from   w w  w  .j  a  v a  2s .co  m*/
        XMLStreamWriter writer = xmloutputf.createXMLStreamWriter(outstream, "UTF-8");
        // do the actual writing using an appropriate Marshaller 
        // and do not forget to flush
        writer.flush();
    } catch (XMLStreamException ex) {
        // Re-throw appropriate i/o or runtime exception
        throw new IOException("Oppsie");
    }
}