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:com.microsoft.windowsazure.storage.table.TableParser.java

/**
 * Reserved for internal use. Writes a single entity to the specified <code>OutputStream</code> as a complete XML
 * document./*from w w  w .j  a v  a2s .c  o  m*/
 * 
 * @param outStream
 *            The <code>OutputStream</code> to write the entity to.
 * @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 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.
 */
private static void writeSingleAtomEntity(final OutputStream outStream, final TableEntity entity,
        final boolean isTableEntry, final OperationContext opContext)
        throws XMLStreamException, StorageException {
    final XMLOutputFactory xmlOutFactoryInst = XMLOutputFactory.newInstance();
    XMLStreamWriter xmlw = xmlOutFactoryInst.createXMLStreamWriter(outStream, Constants.UTF8_CHARSET);

    // default is UTF8
    xmlw.writeStartDocument(Constants.UTF8_CHARSET, "1.0");

    writeAtomEntity(entity, isTableEntry, xmlw, opContext);

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

From source file:com.norconex.jef4.log.FileLogManager.java

@Override
public void saveToXML(Writer out) throws IOException {
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    try {// w  ww .ja v a2s. co m
        XMLStreamWriter writer = factory.createXMLStreamWriter(out);
        writer.writeStartElement("logManager");
        writer.writeAttribute("class", getClass().getCanonicalName());
        writer.writeStartElement("logDir");
        writer.writeCharacters(new File(logdir).getAbsolutePath());
        writer.writeEndElement();
        writer.writeEndElement();
        writer.flush();
        writer.close();
    } catch (XMLStreamException e) {
        throw new IOException("Cannot save as XML.", e);
    }
}

From source file:microsoft.exchange.webservices.data.core.EwsUtilities.java

/**
 * ./*from   w w  w  . j ava2  s  . co  m*/
 *
 * @param entryKind the entry kind
 * @param logEntry  the log entry
 * @return the string
 * @throws XMLStreamException the XML stream exception
 * @throws IOException signals that an I/O exception has occurred.
 */
public static String formatLogMessage(String entryKind, String logEntry)
        throws XMLStreamException, IOException {
    String lineSeparator = System.getProperty("line.separator");
    ByteArrayOutputStream outStream = new ByteArrayOutputStream();
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    XMLStreamWriter writer = factory.createXMLStreamWriter(outStream);
    EwsUtilities.writeTraceStartElement(writer, entryKind, false);
    writer.writeCharacters(lineSeparator);
    writer.writeCharacters(logEntry);
    writer.writeCharacters(lineSeparator);
    writer.writeEndElement();
    writer.writeCharacters(lineSeparator);
    writer.flush();
    writer.close();
    outStream.flush();
    String formattedLogMessage = outStream.toString();
    formattedLogMessage = formattedLogMessage.replaceAll("&apos;", "'");
    formattedLogMessage = formattedLogMessage.replaceAll("&quot;", "\"");
    formattedLogMessage = formattedLogMessage.replaceAll("&gt;", ">");
    formattedLogMessage = formattedLogMessage.replaceAll("&lt;", "<");
    formattedLogMessage = formattedLogMessage.replaceAll("&amp;", "&");
    outStream.close();
    return formattedLogMessage;
}

From source file:com.norconex.collector.http.url.impl.DefaultURLExtractor.java

@Override
public void saveToXML(Writer out) throws IOException {
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    try {/*from w  w w. ja v a 2  s  .c o  m*/
        XMLStreamWriter writer = factory.createXMLStreamWriter(out);
        writer.writeStartElement("urlExtractor");
        writer.writeAttribute("class", getClass().getCanonicalName());
        writer.writeStartElement("maxURLLength");
        writer.writeCharacters(Integer.toString(maxURLLength));
        writer.writeEndElement();
        writer.writeEndElement();
        writer.flush();
        writer.close();
    } catch (XMLStreamException e) {
        throw new IOException("Cannot save as XML.", e);
    }
}

From source file:com.norconex.collector.http.robot.impl.DefaultRobotsMetaProvider.java

@Override
public void saveToXML(Writer out) throws IOException {
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    try {// w  w  w  .  j a  v  a  2s.  c om
        XMLStreamWriter writer = factory.createXMLStreamWriter(out);
        writer.writeStartElement("robotsMeta");
        writer.writeAttribute("class", getClass().getCanonicalName());
        writer.writeStartElement("headersPrefix");
        if (headersPrefix != null) {
            writer.writeCharacters(headersPrefix);
        }
        writer.writeEndElement();
        writer.writeEndElement();
        writer.flush();
        writer.close();
    } catch (XMLStreamException e) {
        throw new IOException("Cannot save as XML.", e);
    }
}

From source file:com.norconex.collector.core.filter.impl.RegexMetadataFilter.java

@Override
public void saveToXML(Writer out) throws IOException {
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    try {//from  w w w  . ja  v a 2s . com
        XMLStreamWriter writer = factory.createXMLStreamWriter(out);
        writer.writeStartElement("filter");
        writer.writeAttribute("class", getClass().getCanonicalName());
        super.saveToXML(writer);
        writer.writeAttribute("caseSensitive", Boolean.toString(caseSensitive));
        writer.writeAttribute("field", field);
        writer.writeCharacters(regex == null ? "" : regex);
        writer.writeEndElement();
        writer.flush();
        writer.close();
    } catch (XMLStreamException e) {
        throw new IOException("Cannot save as XML.", e);
    }
}

From source file:com.norconex.jef4.status.FileJobStatusStore.java

@Override
public void saveToXML(Writer out) throws IOException {
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    try {/*from   w w w. j a v  a2 s .c om*/
        XMLStreamWriter writer = factory.createXMLStreamWriter(out);
        writer.writeStartElement("statusStore");
        writer.writeAttribute("class", getClass().getCanonicalName());
        writer.writeStartElement("statusDir");
        writer.writeCharacters(new File(statusDir).getAbsolutePath());
        writer.writeEndElement();
        writer.writeEndElement();
        writer.flush();
        writer.close();
    } catch (XMLStreamException e) {
        throw new IOException("Cannot save as XML.", e);
    }
}

From source file:dk.statsbiblioteket.util.xml.XMLStepperTest.java

@SuppressWarnings("CallToPrintStackTrace")
private synchronized boolean writerIsCollapsing() {
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    try {/*from  w  w  w . jav  a2s.  c om*/
        XMLStreamWriter out = xmlOutFactory.createXMLStreamWriter(os);
        out.writeStartElement("foo");
        out.writeEndElement();
        out.flush();
        return "<foo />".equals(os.toString());
    } catch (XMLStreamException e) {
        throw new RuntimeException("Unable to determine if XMLStreamWriter collapses empty elements", e);
    }
}

From source file:de.qucosa.webapi.v1.SearchResource.java

private ResponseEntity<String> errorResponse(String message, HttpStatus status) throws XMLStreamException {
    StringWriter sw = new StringWriter();
    XMLStreamWriter w = xmlOutputFactory.createXMLStreamWriter(sw);
    w.writeStartDocument("UTF-8", "1.0");
    w.writeStartElement("Opus");
    w.writeEmptyElement("SearchResult");
    w.writeStartElement("Error");
    w.writeAttribute("message", message);
    w.writeEndElement();/*from   w w  w. j  av a 2  s  .  co  m*/
    w.writeEndElement();
    w.writeEndDocument();
    w.flush();
    return new ResponseEntity<>(sw.toString(), status);
}

From source file:com.norconex.collector.http.fetch.impl.GenericMetadataFetcher.java

@Override
public void saveToXML(Writer out) throws IOException {
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    try {//w w  w.  j a v  a  2 s . c  om
        XMLStreamWriter writer = factory.createXMLStreamWriter(out);
        writer.writeStartElement("httpHeadersFetcher");
        writer.writeAttribute("class", getClass().getCanonicalName());
        writer.writeStartElement("validStatusCodes");
        writer.writeCharacters(StringUtils.join(validStatusCodes, ","));
        writer.writeEndElement();
        writer.writeStartElement("headersPrefix");
        writer.writeCharacters(headersPrefix);
        writer.writeEndElement();
        writer.writeEndElement();
        writer.flush();
        writer.close();
    } catch (XMLStreamException e) {
        throw new IOException("Cannot save as XML.", e);
    }
}