当前位置: 首页>>代码示例>>Java>>正文


Java XMLStreamWriter.flush方法代码示例

本文整理汇总了Java中javax.xml.stream.XMLStreamWriter.flush方法的典型用法代码示例。如果您正苦于以下问题:Java XMLStreamWriter.flush方法的具体用法?Java XMLStreamWriter.flush怎么用?Java XMLStreamWriter.flush使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.xml.stream.XMLStreamWriter的用法示例。


在下文中一共展示了XMLStreamWriter.flush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: generateXML

import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
private void generateXML(XMLStreamWriter writer, String sequence)
        throws XMLStreamException {
    char[] seqArr = sequence.toCharArray();
    writer.writeStartDocument();
    writer.writeStartElement("root");

    // Use writeCharacters( String ) to write characters
    writer.writeStartElement("writeCharactersWithString");
    writer.writeCharacters(sequence);
    writer.writeEndElement();

    // Use writeCharacters( char [], int , int ) to write characters
    writer.writeStartElement("writeCharactersWithArray");
    writer.writeCharacters(seqArr, 0, seqArr.length);
    writer.writeEndElement();

    // Close root element and document
    writer.writeEndElement();
    writer.writeEndDocument();
    writer.flush();
    writer.close();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:SurrogatesTest.java

示例2: writeTo

import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
public void writeTo(SOAPMessage saaj) throws SOAPException {
        try {
            // TODO what about in-scope namespaces
            // Not very efficient consider implementing a stream buffer
            // processor that produces a DOM node from the buffer.
            Transformer t = XmlUtil.newTransformer();
            SOAPHeader header = saaj.getSOAPHeader();
            if (header == null)
                header = saaj.getSOAPPart().getEnvelope().addHeader();
// TODO workaround for oracle xdk bug 16555545, when this bug is fixed the line below can be
// uncommented and all lines below, except the catch block, can be removed.
//            t.transform(epr.asSource(localName), new DOMResult(header));
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            XMLStreamWriter w = XMLOutputFactory.newFactory().createXMLStreamWriter(baos);
            epr.writeTo(localName, w);
            w.flush();
            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
            DocumentBuilderFactory fac = DocumentBuilderFactory.newInstance();
            fac.setNamespaceAware(true);
            Node eprNode = fac.newDocumentBuilder().parse(bais).getDocumentElement();
            Node eprNodeToAdd = header.getOwnerDocument().importNode(eprNode, true);
            header.appendChild(eprNodeToAdd);
        } catch (Exception e) {
            throw new SOAPException(e);
        }
    }
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:27,代码来源:EPRHeader.java

示例3: encode

import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
public ContentType encode(Packet packet, OutputStream out) {
    Message message = packet.getMessage();
    if (message != null && message.hasPayload()) {
        final XMLStreamWriter writer = getXMLStreamWriter(out);
        try {
            writer.writeStartDocument();
            packet.getMessage().writePayloadTo(writer);
            writer.writeEndDocument();
            writer.flush();
        } catch (XMLStreamException e) {
            throw new WebServiceException(e);
        }
    }

    return _contentType;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:17,代码来源:FastInfosetCodec.java

示例4: encode

import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
public ContentType encode(Packet packet, OutputStream out) {
            String encoding = (String) packet.invocationProperties
            .get(XMLConstants.OUTPUT_XML_CHARACTER_ENCODING);

    XMLStreamWriter writer = null;

            if (encoding != null && encoding.length() > 0) {
        writer = XMLStreamWriterFactory.create(out, encoding);
    } else {
        writer = XMLStreamWriterFactory.create(out);
    }

    try {
        if (packet.getMessage().hasPayload()){
            writer.writeStartDocument();
            packet.getMessage().writePayloadTo(writer);
            writer.flush();
        }
    } catch (XMLStreamException e) {
        throw new WebServiceException(e);
    }
    return contentType;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:24,代码来源:XMLCodec.java

示例5: testWriteComment

import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
/**
 * Test of main method, of class TestXMLStreamWriter.
 */
@Test
public void testWriteComment() {
    try {
        String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><a:html href=\"http://java.sun.com\"><!--This is comment-->java.sun.com</a:html>";
        XMLOutputFactory f = XMLOutputFactory.newInstance();
        // f.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES,
        // Boolean.TRUE);
        StringWriter sw = new StringWriter();
        XMLStreamWriter writer = f.createXMLStreamWriter(sw);
        writer.writeStartDocument("UTF-8", "1.0");
        writer.writeStartElement("a", "html", "http://www.w3.org/TR/REC-html40");
        writer.writeAttribute("href", "http://java.sun.com");
        writer.writeComment("This is comment");
        writer.writeCharacters("java.sun.com");
        writer.writeEndElement();
        writer.writeEndDocument();
        writer.flush();
        sw.flush();
        StringBuffer sb = sw.getBuffer();
        System.out.println("sb:" + sb.toString());
        Assert.assertTrue(sb.toString().equals(xml));
    } catch (Exception ex) {
        Assert.fail("Exception: " + ex.getMessage());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:XMLStreamWriterTest.java

示例6: writeTo

import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
public void writeTo(SOAPMessage saaj) throws SOAPException {
        try {
            // TODO what about in-scope namespaces
            // Not very efficient consider implementing a stream buffer
            // processor that produces a DOM node from the buffer.
            Transformer t = XmlUtil.newTransformer();
            SOAPHeader header = saaj.getSOAPHeader();
            if (header == null)
                header = saaj.getSOAPPart().getEnvelope().addHeader();
// TODO workaround for oracle xdk bug 16555545, when this bug is fixed the line below can be
// uncommented and all lines below, except the catch block, can be removed.
//            t.transform(epr.asSource(localName), new DOMResult(header));
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            XMLStreamWriter w = XMLOutputFactory.newFactory().createXMLStreamWriter(baos);
            epr.writeTo(localName, w);
            w.flush();
            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
            DocumentBuilderFactory fac = XmlUtil.newDocumentBuilderFactory(false);
            fac.setNamespaceAware(true);
            Node eprNode = fac.newDocumentBuilder().parse(bais).getDocumentElement();
            Node eprNodeToAdd = header.getOwnerDocument().importNode(eprNode, true);
            header.appendChild(eprNodeToAdd);
        } catch (Exception e) {
            throw new SOAPException(e);
        }
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:EPRHeader.java

示例7: print

import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
/**
 * Outputs a Smile representation of the Protocol Message supplied into the parameter output.
 * (This representation is the new version of the classic "ProtocolPrinter" output from the
 * original Protocol Buffer system)
 */
public void print(Message message, XMLStreamWriter generator) throws IOException {
    try {
        final String messageName = message.getDescriptorForType().getName();
    	generator.writeStartElement(messageName);    	
    	printMessage(message, generator);
        generator.writeEndElement();
        generator.flush();
    } catch (XMLStreamException e) {
        throw new IOException(e);
    }
}
 
开发者ID:jigsaw-projects,项目名称:jigsaw-payment,代码行数:17,代码来源:XmlJavaxFormat.java

示例8: writeTo

import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
@Override
public void writeTo(HashMap hashMap, Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> multivaluedMap, OutputStream outputStream) throws IOException, WebApplicationException {
	try {
		XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
		XMLStreamWriter xmlWriter = outputFactory.createXMLStreamWriter(outputStream);
		xmlWriter.writeStartElement("entity");
		writeValue(hashMap, xmlWriter);
		xmlWriter.writeEndElement();
		xmlWriter.flush();
		xmlWriter.close();
	} catch (XMLStreamException e) {
		throw new IOException(e);
	}
}
 
开发者ID:marrow16,项目名称:Nasapi,代码行数:15,代码来源:XmlHashMapBodyWriter.java

示例9: producePureXMLLogoutRequest

import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
private ByteArrayOutputStream producePureXMLLogoutRequest(String logoutUrl, String nameID, String format, String sessionIndex, String issuer, String issueInstant) throws XMLStreamException, UnsupportedEncodingException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    XMLStreamWriter writer = factory.createXMLStreamWriter(baos);

    writer.writeStartElement("saml2p", "LogoutRequest", "urn:oasis:names:tc:SAML:2.0:protocol");
    writer.writeNamespace("saml2p", "urn:oasis:names:tc:SAML:2.0:protocol");
    writer.writeAttribute("ID", "_" + UUID.randomUUID().toString());
    writer.writeAttribute("Version", "2.0");
    writer.writeAttribute("Destination", logoutUrl);
    writer.writeAttribute("IssueInstant", issueInstant + "Z");

    writer.writeStartElement("saml2", "Issuer", "urn:oasis:names:tc:SAML:2.0:assertion");
    writer.writeNamespace("saml2", "urn:oasis:names:tc:SAML:2.0:assertion");
    writer.writeCharacters(issuer);
    writer.writeEndElement();

    writer.writeStartElement("saml", "NameID", "urn:oasis:names:tc:SAML:2.0:assertion");
    writer.writeNamespace("saml", "urn:oasis:names:tc:SAML:2.0:assertion");
    writer.writeAttribute("Format", format);
    writer.writeCharacters(nameID);
    writer.writeEndElement();

    writer.writeStartElement("saml2p", "SessionIndex", "urn:oasis:names:tc:SAML:2.0:protocol");
    writer.writeCharacters(sessionIndex);
    writer.writeEndElement();

    writer.writeEndElement();
    writer.flush();

    return baos;
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:33,代码来源:LogoutRequestGenerator.java

示例10: writeTo

import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
public void writeTo(XMLStreamWriter writer) throws XMLStreamException {
    try {
        writer.writeStartDocument();
        if (!parsedMessage) {
            DOMUtil.serializeNode(sm.getSOAPPart().getEnvelope(), writer);
        } else {
            SOAPEnvelope env = sm.getSOAPPart().getEnvelope();
            DOMUtil.writeTagWithAttributes(env, writer);
            if (hasHeaders()) {
                if(env.getHeader() != null) {
                    DOMUtil.writeTagWithAttributes(env.getHeader(), writer);
                } else {
                    writer.writeStartElement(env.getPrefix(), "Header", env.getNamespaceURI());
                }
                for (Header h : headers.asList()) {
                    h.writeTo(writer);
                }
                writer.writeEndElement();
            }

            DOMUtil.serializeNode(sm.getSOAPBody(), writer);
            writer.writeEndElement();
        }
        writer.writeEndDocument();
        writer.flush();
    } catch (SOAPException ex) {
        throw new XMLStreamException2(ex);
        //for now. ask jaxws team what to do.
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:31,代码来源:SAAJMessage.java

示例11: encode

import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
public ContentType encode(Packet packet, OutputStream out) {
    if (packet.getMessage() != null) {
        final XMLStreamWriter writer = getXMLStreamWriter(out);
        try {
            packet.getMessage().writeTo(writer);
            writer.flush();
        } catch (XMLStreamException e) {
            throw new WebServiceException(e);
        }
    }
    return getContentType(packet.soapAction);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:13,代码来源:FastInfosetStreamSOAPCodec.java

示例12: encode

import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
public ContentType encode(Packet packet, OutputStream out) {
    if (packet.getMessage() != null) {
        String encoding = getPacketEncoding(packet);
        packet.invocationProperties.remove(DECODED_MESSAGE_CHARSET);
        XMLStreamWriter writer = XMLStreamWriterFactory.create(out, encoding);
        try {
            packet.getMessage().writeTo(writer);
            writer.flush();
        } catch (XMLStreamException e) {
            throw new WebServiceException(e);
        }
        XMLStreamWriterFactory.recycle(writer);
    }
    return getContentType(packet);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:16,代码来源:StreamSOAPCodec.java

示例13: toString

import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
@Override
public String toString() {
  StringBuilder buf = new StringBuilder();
  buf.append(super.toString());
  String content;
    try {
        Message msg = getMessage();
    if (msg != null) {
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    XMLStreamWriter xmlWriter = XMLStreamWriterFactory.create(baos, "UTF-8");
                    msg.copy().writeTo(xmlWriter);
                    xmlWriter.flush();
                    xmlWriter.close();
                    baos.flush();
                    XMLStreamWriterFactory.recycle(xmlWriter);

                    byte[] bytes = baos.toByteArray();
                    //message = Messages.create(XMLStreamReaderFactory.create(null, new ByteArrayInputStream(bytes), "UTF-8", true));
                    content = new String(bytes, "UTF-8");
            } else {
                content = "<none>";
    }
    } catch (Throwable t) {
            throw new WebServiceException(t);
    }
  buf.append(" Content: ").append(content);
  return buf.toString();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:Packet.java

示例14: testCR6420953

import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
@Test
public void testCR6420953() {

    try {
        XMLOutputFactory xof = XMLOutputFactory.newInstance();
        StringWriter sw = new StringWriter();
        XMLStreamWriter w = xof.createXMLStreamWriter(sw);

        w.writeStartDocument();
        w.writeStartElement("element");

        w.writeDefaultNamespace(XML_CONTENT);
        w.writeNamespace("prefix", XML_CONTENT);

        w.writeAttribute("attribute", XML_CONTENT);
        w.writeAttribute(XML_CONTENT, "attribute2", XML_CONTENT);
        w.writeAttribute("prefix", XML_CONTENT, "attribute3", XML_CONTENT);

        w.writeCharacters("\n");
        w.writeCharacters(XML_CONTENT);
        w.writeCharacters("\n");
        w.writeCharacters(XML_CONTENT.toCharArray(), 0, XML_CONTENT.length());
        w.writeCharacters("\n");

        w.writeEndElement();
        w.writeEndDocument();
        w.flush();

        System.out.println(sw);

        // make sure that the generated XML parses
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        dbf.newDocumentBuilder().parse(new InputSource(new StringReader(sw.toString())));
    } catch (XMLStreamException xmlStreamException) {
        xmlStreamException.printStackTrace();
        Assert.fail(xmlStreamException.toString());
    } catch (SAXException saxException) {
        saxException.printStackTrace();
        Assert.fail(saxException.toString());
    } catch (ParserConfigurationException parserConfigurationException) {
        parserConfigurationException.printStackTrace();
        Assert.fail(parserConfigurationException.toString());
    } catch (IOException ioException) {
        ioException.printStackTrace();
        Assert.fail(ioException.toString());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:49,代码来源:AttributeEscapeTest.java

示例15: sendVehicleStatusReport

import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
private void sendVehicleStatusReport() throws XMLStreamException, IOException {
    boolean sendMessage = false;
    double x = 0;
    double y = 0;
    synchronized (currentPoint) {
        if (null != currentPoint && !currentPoint.isEmpty()) {
            sendMessage = true;
            x = currentPoint.getX();
            y = currentPoint.getY();
        }
    }
    if (sendMessage) {
        StringWriter xmlStringWriter = new StringWriter();
        XMLStreamWriter xmlStreamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(xmlStringWriter);
        xmlStreamWriter.writeStartDocument();
        xmlStreamWriter.writeStartElement("geomessages");
        xmlStreamWriter.writeStartElement("geomessage");
        xmlStreamWriter.writeAttribute("v", Utilities.GEOMESSAGE_VERSION);

        Utilities.writeTextElement(xmlStreamWriter,
                MessageHelper.MESSAGE_2525C_TYPE_PROPERTY_NAME, "sysmsg");
        Utilities.writeTextElement(xmlStreamWriter,
                MessageHelper.MESSAGE_ACTION_PROPERTY_NAME, "UPDATE");
        Utilities.writeTextElement(xmlStreamWriter,
                MessageHelper.MESSAGE_ID_PROPERTY_NAME, UUID.randomUUID().toString());
        Utilities.writeTextElement(xmlStreamWriter,
                MessageHelper.MESSAGE_WKID_PROPERTY_NAME, Integer.toString(Utilities.WGS84.getID()));
        Utilities.writeTextElement(xmlStreamWriter,
                MessageHelper.MESSAGE_2525C_CONTROL_POINTS_PROPERTY_NAME,
                x + "," + y);
        Utilities.writeTextElement(xmlStreamWriter, "uniquedesignation", appConfig.getUsername());
        Utilities.writeTextElement(xmlStreamWriter, "type", appConfig.getVehicleType());
        String dateString = Utilities.DATE_FORMAT_GEOMESSAGE.format(new Date());
        Utilities.writeTextElement(xmlStreamWriter, "datetimevalid", dateString);
        Utilities.writeTextElement(xmlStreamWriter, "fuel_state", "100");
        Utilities.writeTextElement(xmlStreamWriter, 
                "1.0".equals(appConfig.getGeomessageVersion()) ? "sys_msg" : "system_msgs",
                "Operational");
        for (int i = 1; i <= 4; i++) {
            /**
             * Status coded values:
             * 1 = Operational
             * 2 = Advisory
             * 3 = Critical
             * 4 = Inoperable
             */
            Utilities.writeTextElement(xmlStreamWriter, "sys_status_" + i, "1");
        }

        xmlStreamWriter.writeEndElement(); // geomessage
        xmlStreamWriter.writeEndElement(); // geomessages
        xmlStreamWriter.writeEndDocument();
        xmlStreamWriter.flush();
        String messageText = xmlStringWriter.toString();
        messageController.sendMessage(messageText.getBytes());
    }
}
 
开发者ID:Esri,项目名称:defense-solutions-proofs-of-concept,代码行数:58,代码来源:VehicleStatusController.java


注:本文中的javax.xml.stream.XMLStreamWriter.flush方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。