java类javax.xml.stream.XMLOutputFactory的实例源码

StaxDemo.java 文件源码 项目:JavaCommon 阅读 18 收藏 0 点赞 0 评论 0
public static void writeXMLByStAX() throws XMLStreamException, FileNotFoundException {
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    XMLStreamWriter writer = factory.createXMLStreamWriter(new FileOutputStream("output.xml"));
    writer.writeStartDocument();
    writer.writeCharacters(" ");
    writer.writeComment("testing comment");
    writer.writeCharacters(" ");
    writer.writeStartElement("catalogs");
    writer.writeNamespace("myNS", "http://blog.csdn.net/Chinajash");
    writer.writeAttribute("owner", "sina");
    writer.writeCharacters(" ");
    writer.writeStartElement("http://blog.csdn.net/Chinajash", "catalog");
    writer.writeAttribute("id", "007");
    writer.writeCharacters("Apparel");
    // 写入catalog元素的结束标签
    writer.writeEndElement();
    // 写入catalogs元素的结束标签
    writer.writeEndElement();
    // 结束 XML 文档
    writer.writeEndDocument();
    writer.close();
    System.out.println("ok");
}
DocumentStaxUtils.java 文件源码 项目:gate-core 阅读 32 收藏 0 点赞 0 评论 0
public static void writeDocument(Document doc, OutputStream outputStream, String namespaceURI) throws XMLStreamException, IOException {
  if(outputFactory == null) {
    outputFactory = XMLOutputFactory.newInstance();
  }

  XMLStreamWriter xsw = null;
  try {
    if(doc instanceof TextualDocument) {
      xsw = outputFactory.createXMLStreamWriter(outputStream,
              ((TextualDocument)doc).getEncoding());
      xsw.writeStartDocument(((TextualDocument)doc).getEncoding(), "1.0");
    }
    else {
      xsw = outputFactory.createXMLStreamWriter(outputStream);
      xsw.writeStartDocument("1.0");
    }
    newLine(xsw);

    writeDocument(doc, xsw, namespaceURI);
  }
  finally {
    if(xsw != null) {
      xsw.close();
    }
  }
}
EPRHeader.java 文件源码 项目:OpenJSharp 阅读 19 收藏 0 点赞 0 评论 0
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);
        }
    }
XMLStreamWriterImpl.java 文件源码 项目:OpenJSharp 阅读 23 收藏 0 点赞 0 评论 0
/**
 * Initialize an instance of this XMLStreamWriter. Allocate new instances
 * for all the data structures. Set internal flags based on property values.
 */
private void init() {
    fReuse = false;
    fNamespaceDecls = new ArrayList();
    fPrefixGen = new Random();
    fAttributeCache = new ArrayList();
    fInternalNamespaceContext = new NamespaceSupport();
    fInternalNamespaceContext.reset();
    fNamespaceContext = new NamespaceContextImpl();
    fNamespaceContext.internalContext = fInternalNamespaceContext;

    // Set internal state based on property values
    Boolean ob = (Boolean) fPropertyManager.getProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES);
    fIsRepairingNamespace = ob.booleanValue();
    ob = (Boolean) fPropertyManager.getProperty(Constants.ESCAPE_CHARACTERS);
    setEscapeCharacters(ob.booleanValue());
}
XMLStreamWriterImpl.java 文件源码 项目:OpenJSharp 阅读 19 收藏 0 点赞 0 评论 0
/**
 * Reset this instance so that it can be re-used. Clears but does not
 * re-allocate internal data structures.
 *
 * @param resetProperties Indicates if properties should be read again
 */
void reset(boolean resetProperties) {
    if (!fReuse) {
        throw new java.lang.IllegalStateException(
            "close() Must be called before calling reset()");
    }

    fReuse = false;
    fNamespaceDecls.clear();
    fAttributeCache.clear();

    // reset Element/NamespaceContext stacks
    fElementStack.clear();
    fInternalNamespaceContext.reset();

    fStartTagOpened = false;
    fNamespaceContext.userContext = null;

    if (resetProperties) {
        Boolean ob = (Boolean) fPropertyManager.getProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES);
        fIsRepairingNamespace = ob.booleanValue();
        ob = (Boolean) fPropertyManager.getProperty(Constants.ESCAPE_CHARACTERS);
        setEscapeCharacters(ob.booleanValue());
    }
}
EPRHeader.java 文件源码 项目:openjdk-jdk10 阅读 24 收藏 0 点赞 0 评论 0
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);
        }
    }
XMLStreamWriterImpl.java 文件源码 项目:openjdk-jdk10 阅读 25 收藏 0 点赞 0 评论 0
/**
 * Initialize an instance of this XMLStreamWriter. Allocate new instances
 * for all the data structures. Set internal flags based on property values.
 */
private void init() {
    fReuse = false;
    fNamespaceDecls = new ArrayList<>();
    fPrefixGen = new Random();
    fAttributeCache = new ArrayList<>();
    fInternalNamespaceContext = new NamespaceSupport();
    fInternalNamespaceContext.reset();
    fNamespaceContext = new NamespaceContextImpl();
    fNamespaceContext.internalContext = fInternalNamespaceContext;

    // Set internal state based on property values
    Boolean ob = (Boolean) fPropertyManager.getProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES);
    fIsRepairingNamespace = ob;
    ob = (Boolean) fPropertyManager.getProperty(Constants.ESCAPE_CHARACTERS);
    setEscapeCharacters(ob);
}
XMLStreamWriterImpl.java 文件源码 项目:openjdk-jdk10 阅读 22 收藏 0 点赞 0 评论 0
/**
 * Reset this instance so that it can be re-used. Clears but does not
 * re-allocate internal data structures.
 *
 * @param resetProperties Indicates if properties should be read again
 */
void reset(boolean resetProperties) {
    if (!fReuse) {
        throw new java.lang.IllegalStateException(
            "close() Must be called before calling reset()");
    }

    fReuse = false;
    fNamespaceDecls.clear();
    fAttributeCache.clear();

    // reset Element/NamespaceContext stacks
    fElementStack.clear();
    fInternalNamespaceContext.reset();

    fStartTagOpened = false;
    fNamespaceContext.userContext = null;

    if (resetProperties) {
        Boolean ob = (Boolean) fPropertyManager.getProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES);
        fIsRepairingNamespace = ob;
        ob = (Boolean) fPropertyManager.getProperty(Constants.ESCAPE_CHARACTERS);
        setEscapeCharacters(ob);
    }
}
DefaultAttributeTest.java 文件源码 项目:openjdk-jdk10 阅读 19 收藏 0 点赞 0 评论 0
@Test
public void testStreamReader() {
    XMLInputFactory ifac = XMLInputFactory.newInstance();
    XMLOutputFactory ofac = XMLOutputFactory.newInstance();

    try {
        ifac.setProperty(ifac.IS_REPLACING_ENTITY_REFERENCES, new Boolean(false));

        XMLStreamReader re = ifac.createXMLStreamReader(this.getClass().getResource(INPUT_FILE).toExternalForm(),
                this.getClass().getResourceAsStream(INPUT_FILE));

        while (re.hasNext()) {
            int event = re.next();
            if (event == XMLStreamConstants.START_ELEMENT && re.getLocalName().equals("bookurn")) {
                Assert.assertTrue(re.getAttributeCount() == 0, "No attributes are expected for <bookurn> ");
                Assert.assertTrue(re.getNamespaceCount() == 2, "Two namespaces are expected for <bookurn> ");
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail("Exception occured: " + e.getMessage());
    }
}
XMLEventWriterTest.java 文件源码 项目:openjdk-jdk10 阅读 27 收藏 0 点赞 0 评论 0
/**
 * Test XMLStreamWriter parsing a file with an external entity reference.
 */
@Test
public void testXMLStreamWriter() {

    try {
        XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
        XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(System.out);
        XMLInputFactory inputFactory = XMLInputFactory.newInstance();
        String file = getClass().getResource("XMLEventWriterTest.xml").getPath();
        XMLEventReader eventReader = inputFactory.createXMLEventReader(new StreamSource(new File(file)));

        // adds the event to the consumer.
        eventWriter.add(eventReader);
        eventWriter.flush();
        eventWriter.close();

        // expected success
    } catch (Exception exception) {
        exception.printStackTrace();
        Assert.fail(exception.toString());
    }
}
Bug7037352Test.java 文件源码 项目:openjdk-jdk10 阅读 21 收藏 0 点赞 0 评论 0
@Test
public void test() {
    try {
        XMLOutputFactory xof = XMLOutputFactory.newInstance();
        StreamResult sr = new StreamResult();
        XMLStreamWriter xsw = xof.createXMLStreamWriter(sr);
        NamespaceContext nc = xsw.getNamespaceContext();
        System.out.println(nc.getPrefix(XMLConstants.XML_NS_URI));
        System.out.println("  expected result: " + XMLConstants.XML_NS_PREFIX);
        System.out.println(nc.getPrefix(XMLConstants.XMLNS_ATTRIBUTE_NS_URI));
        System.out.println("  expected result: " + XMLConstants.XMLNS_ATTRIBUTE);

        Assert.assertTrue(nc.getPrefix(XMLConstants.XML_NS_URI) == XMLConstants.XML_NS_PREFIX);
        Assert.assertTrue(nc.getPrefix(XMLConstants.XMLNS_ATTRIBUTE_NS_URI) == XMLConstants.XMLNS_ATTRIBUTE);

    } catch (Throwable ex) {
        Assert.fail(ex.toString());
    }
}
XMLStreamWriterTest.java 文件源码 项目:openjdk-jdk10 阅读 20 收藏 0 点赞 0 评论 0
/**
 * @bug 8139584
 * Verifies that the resulting XML contains the standalone setting.
 */
@Test
public void testCreateStartDocument() throws XMLStreamException {

    StringWriter stringWriter = new StringWriter();
    XMLOutputFactory out = XMLOutputFactory.newInstance();
    XMLEventFactory eventFactory = XMLEventFactory.newInstance();

    XMLEventWriter eventWriter = out.createXMLEventWriter(stringWriter);

    XMLEvent event = eventFactory.createStartDocument("iso-8859-15", "1.0", true);
    eventWriter.add(event);
    eventWriter.flush();
    Assert.assertTrue(stringWriter.toString().contains("encoding=\"iso-8859-15\""));
    Assert.assertTrue(stringWriter.toString().contains("version=\"1.0\""));
    Assert.assertTrue(stringWriter.toString().contains("standalone=\"yes\""));
}
XMLStreamWriterTest.java 文件源码 项目:openjdk-jdk10 阅读 22 收藏 0 点赞 0 评论 0
/**
 * @bug 8139584
 * Verifies that the resulting XML contains the standalone setting.
 */
@Test
public void testCreateStartDocument_DOMWriter()
        throws ParserConfigurationException, XMLStreamException {

    XMLOutputFactory xof = XMLOutputFactory.newInstance();
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document doc = db.newDocument();
    XMLEventWriter eventWriter = xof.createXMLEventWriter(new DOMResult(doc));
    XMLEventFactory eventFactory = XMLEventFactory.newInstance();
    XMLEvent event = eventFactory.createStartDocument("iso-8859-15", "1.0", true);
    eventWriter.add(event);
    eventWriter.flush();
    Assert.assertEquals(doc.getXmlEncoding(), "iso-8859-15");
    Assert.assertEquals(doc.getXmlVersion(), "1.0");
    Assert.assertTrue(doc.getXmlStandalone());
}
XMLStreamWriterTest.java 文件源码 项目:openjdk-jdk10 阅读 27 收藏 0 点赞 0 评论 0
/**
 * 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());
    }
}
UnprefixedNameTest.java 文件源码 项目:openjdk-jdk10 阅读 18 收藏 0 点赞 0 评论 0
@Test
public void testUnboundPrefix() throws Exception {

    try {
        XMLOutputFactory xof = XMLOutputFactory.newInstance();
        XMLStreamWriter w = xof.createXMLStreamWriter(System.out);
        // here I'm trying to write
        // <bar xmlns="foo" />
        w.writeStartDocument();
        w.writeStartElement("foo", "bar");
        w.writeDefaultNamespace("foo");
        w.writeCharacters("---");
        w.writeEndElement();
        w.writeEndDocument();
        w.close();

        // Unexpected success
        String FAIL_MSG = "Unexpected success.  Expected: " + "XMLStreamException - " + "if the namespace URI has not been bound to a prefix "
                + "and javax.xml.stream.isPrefixDefaulting has not been " + "set to true";
        System.err.println(FAIL_MSG);
        Assert.fail(FAIL_MSG);
    } catch (XMLStreamException xmlStreamException) {
        // Expected Exception
        System.out.println("Expected XMLStreamException: " + xmlStreamException.toString());
    }
}
UnprefixedNameTest.java 文件源码 项目:openjdk-jdk10 阅读 18 收藏 0 点赞 0 评论 0
@Test
public void testBoundPrefix() throws Exception {

    try {
        XMLOutputFactory xof = XMLOutputFactory.newInstance();
        XMLStreamWriter w = xof.createXMLStreamWriter(System.out);
        // here I'm trying to write
        // <bar xmlns="foo" />
        w.writeStartDocument();
        w.writeStartElement("foo", "bar", "http://namespace");
        w.writeCharacters("---");
        w.writeEndElement();
        w.writeEndDocument();
        w.close();

        // Expected success
        System.out.println("Expected success.");
    } catch (Exception exception) {
        // Unexpected Exception
        String FAIL_MSG = "Unexpected Exception: " + exception.toString();
        System.err.println(FAIL_MSG);
        Assert.fail(FAIL_MSG);
    }
}
NamespaceTest.java 文件源码 项目:openjdk-jdk10 阅读 20 收藏 0 点赞 0 评论 0
@BeforeMethod
public void setUp() {

    // want a Factory that repairs Namespaces
    xmlOutputFactory = XMLOutputFactory.newInstance();
    xmlOutputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);

    // new OutputStream
    byteArrayOutputStream = new ByteArrayOutputStream();

    // new Writer
    try {
        xmlStreamWriter = xmlOutputFactory.createXMLStreamWriter(byteArrayOutputStream, "utf-8");

    } catch (XMLStreamException xmlStreamException) {
        Assert.fail(xmlStreamException.toString());
    }
}
Bug6846132Test.java 文件源码 项目:openjdk-jdk10 阅读 22 收藏 0 点赞 0 评论 0
@Test
public void testSAXResult() {
    DefaultHandler handler = new DefaultHandler();

    final String EXPECTED_OUTPUT = "<?xml version=\"1.0\"?><root></root>";
    try {
        SAXResult saxResult = new SAXResult(handler);
        // saxResult.setSystemId("jaxp-ri/unit-test/javax/xml/stream/XMLOutputFactoryTest/cr6846132.xml");
        XMLOutputFactory ofac = XMLOutputFactory.newInstance();
        XMLStreamWriter writer = ofac.createXMLStreamWriter(saxResult);
        writer.writeStartDocument("1.0");
        writer.writeStartElement("root");
        writer.writeEndElement();
        writer.writeEndDocument();
        writer.flush();
        writer.close();
    } catch (Exception e) {
        if (e instanceof UnsupportedOperationException) {
            // expected
        } else {
            e.printStackTrace();
            Assert.fail(e.toString());
        }
    }
}
Bug6846132Test.java 文件源码 项目:openjdk-jdk10 阅读 23 收藏 0 点赞 0 评论 0
@Test
public void testSAXResult1() {
    DefaultHandler handler = new DefaultHandler();

    try {
        SAXResult saxResult = new SAXResult(handler);
        XMLOutputFactory ofac = XMLOutputFactory.newInstance();
        XMLEventWriter writer = ofac.createXMLEventWriter(saxResult);
    } catch (Exception e) {
        if (e instanceof UnsupportedOperationException) {
            // expected
        } else {
            e.printStackTrace();
            Assert.fail(e.toString());
        }
    }
}
StreamResultTest.java 文件源码 项目:openjdk-jdk10 阅读 22 收藏 0 点赞 0 评论 0
@Test
public void testStreamResult() {
    final String EXPECTED_OUTPUT = "<?xml version=\"1.0\"?><root></root>";
    try {
        XMLOutputFactory ofac = XMLOutputFactory.newInstance();
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        StreamResult sr = new StreamResult(buffer);
        XMLStreamWriter writer = ofac.createXMLStreamWriter(sr);
        writer.writeStartDocument("1.0");
        writer.writeStartElement("root");
        writer.writeEndElement();
        writer.writeEndDocument();
        writer.close();
        Assert.assertEquals(buffer.toString(), EXPECTED_OUTPUT);
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail(e.toString());
    }
}
StreamResultTest.java 文件源码 项目:openjdk-jdk10 阅读 24 收藏 0 点赞 0 评论 0
@Test
public void testStreamWriterWithStAXResultNStreamWriter() {
    final String EXPECTED_OUTPUT = "<?xml version=\"1.0\"?><root></root>";

    try {
        XMLOutputFactory ofac = XMLOutputFactory.newInstance();
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        XMLStreamWriter writer = ofac.createXMLStreamWriter(buffer);
        StAXResult res = new StAXResult(writer);
        writer = ofac.createXMLStreamWriter(res);
        writer.writeStartDocument("1.0");
        writer.writeStartElement("root");
        writer.writeEndElement();
        writer.writeEndDocument();
        writer.close();
        Assert.assertEquals(buffer.toString(), EXPECTED_OUTPUT);
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail(e.toString());
    }
}
PropertiesPlatformConfig.java 文件源码 项目:powsybl-core 阅读 22 收藏 0 点赞 0 评论 0
public static void writeXml(Path configDir, Path xmlFile) throws IOException, XMLStreamException {
    XMLOutputFactory output = XMLOutputFactory.newInstance();
    try (Writer writer = Files.newBufferedWriter(xmlFile, StandardCharsets.UTF_8)) {
        XMLStreamWriter xmlWriter = output.createXMLStreamWriter(writer);
        try {
            xmlWriter.writeStartDocument(StandardCharsets.UTF_8.toString(), "1.0");
            xmlWriter.writeStartElement("config");
            try (DirectoryStream<Path> ds = Files.newDirectoryStream(configDir, entry -> Files.isRegularFile(entry) && entry.getFileName().toString().endsWith(".properties"))) {
                for (Path file : ds) {
                    String fileName = file.getFileName().toString();
                    String fileNameWithoutExtension = fileName.substring(0, fileName.length() - 11);
                    xmlWriter.writeStartElement(fileNameWithoutExtension);
                    Properties properties = new Properties();
                    try (Reader reader = Files.newBufferedReader(file, StandardCharsets.UTF_8)) {
                        properties.load(reader);
                    }
                    for (String name : properties.stringPropertyNames()) {
                        String value = properties.getProperty(name);
                        xmlWriter.writeStartElement(name);
                        xmlWriter.writeCharacters(value);
                        xmlWriter.writeEndElement();
                    }
                    xmlWriter.writeEndElement();
                }
            }
            xmlWriter.writeEndElement();
            xmlWriter.writeEndDocument();
        } finally {
            xmlWriter.close();
        }
    }
}
Exporter.java 文件源码 项目:activemq-cli-tools 阅读 22 收藏 0 点赞 0 评论 0
public static void exportStore(final ExportConfiguration config) throws Exception {

        if (!config.isOverwrite() && config.getTarget().exists()) {
            throw new IllegalStateException("File: " + config.getTarget() + " already exists");
        }

        long start = System.currentTimeMillis();
        try(OutputStream fos = new BufferedOutputStream(config.isCompress() ? new GZIPOutputStream(
                new FileOutputStream(config.getTarget())) : new FileOutputStream(config.getTarget()))) {

            final XMLStreamWriter xmlWriter = XMLOutputFactory.newFactory().createXMLStreamWriter(fos);
            final ArtemisJournalMarshaller xmlMarshaller = new ArtemisJournalMarshaller(xmlWriter);

            xmlMarshaller.appendJournalOpen();

            if (config.isMultiKaha()) {
                appendMultiKahaDbStore(xmlMarshaller, getMultiKahaDbAdapter(config.getSource()),
                        config.getQueuePattern(), config.getTopicPattern());
            } else {
                appendKahaDbStore(xmlMarshaller, getKahaDbAdapter(config.getSource()),
                        config.getQueuePattern(), config.getTopicPattern());
            }

            xmlMarshaller.appendJournalClose(true);
        }

        long end = System.currentTimeMillis();

        LOG.info("Total export time: " + (end - start) + " ms");
    }
ArtemisJournalMarshallerTest.java 文件源码 项目:activemq-cli-tools 阅读 19 收藏 0 点赞 0 评论 0
/**
 * Test stream marshal by appending one message at a time
 *
 * @throws Exception
 */
@Test
public void testStreamMarshal() throws Exception {
    File file = tempFolder.newFile();

    try(FileOutputStream fos = new FileOutputStream(file)) {
        XMLStreamWriter xmlWriter = XMLOutputFactory.newFactory().createXMLStreamWriter(fos);
        ArtemisJournalMarshaller xmlMarshaller = new ArtemisJournalMarshaller(xmlWriter);

        xmlMarshaller.appendJournalOpen();
        xmlMarshaller.appendBindingsElement();
        xmlMarshaller.appendBinding(new AddressBindingType());
        xmlMarshaller.appendEndElement();
        xmlMarshaller.appendMessagesElement();

        //Marshal messages one at a time
        for (int i = 0; i < 3; i++) {
            MessageType message = new MessageType();
            message.setId((long) i);
            message.setTimestamp(System.currentTimeMillis());
            xmlMarshaller.appendMessage(message);
        }

        xmlMarshaller.appendEndElement();
        xmlMarshaller.appendJournalClose(true);
    }

    //This can be read as a stream as well but for the purpose of this test
    //just read the whole thing in at once
    validate(file);
}
Serialization.java 文件源码 项目:DocIT 阅读 33 收藏 0 点赞 0 评论 0
public static void serializeCompany(File output, Company c)
throws  JAXBException,
        FileNotFoundException,
        XMLStreamException 
{
    initializeJaxbContext();
    OutputStream os = new FileOutputStream(output);
    Marshaller marshaller = jaxbContext.createMarshaller();
    XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
       XMLStreamWriter writer = outputFactory.createXMLStreamWriter(os);
    marshaller.marshal(c, writer); // TODO: need a stream writer that does indentation      
}
Serialization.java 文件源码 项目:DocIT 阅读 30 收藏 0 点赞 0 评论 0
public static void serializeCompany(File output, Company c)
throws  JAXBException,
        FileNotFoundException,
        XMLStreamException 
{
    initializeJaxbContext();
    OutputStream os = new FileOutputStream(output);
    Marshaller marshaller = jaxbContext.createMarshaller();
    XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
       XMLStreamWriter writer = outputFactory.createXMLStreamWriter(os);
    marshaller.marshal(c, writer); // TODO: need a stream writer that does indentation      
}
Serialization.java 文件源码 项目:DocIT 阅读 21 收藏 0 点赞 0 评论 0
public static void writeCompany(File output, Company c)
throws  JAXBException,
        FileNotFoundException,
        XMLStreamException 
{
    initializeJaxbContext();
    OutputStream os = new FileOutputStream(output);
    Marshaller marshaller = jaxbContext.createMarshaller();
    XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
       XMLStreamWriter writer = outputFactory.createXMLStreamWriter(os);
    marshaller.marshal(c, writer); // TODO: need a stream writer that does indentation      
}
Serialization.java 文件源码 项目:DocIT 阅读 22 收藏 0 点赞 0 评论 0
public static void writeCompany(File output, Company c)
throws  JAXBException,
        FileNotFoundException,
        XMLStreamException 
{
    initializeJaxbContext();
    OutputStream os = new FileOutputStream(output);
    Marshaller marshaller = jaxbContext.createMarshaller();
    XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
       XMLStreamWriter writer = outputFactory.createXMLStreamWriter(os);
    marshaller.marshal(c, writer); // TODO: need a stream writer that does indentation      
}
Serialization.java 文件源码 项目:DocIT 阅读 26 收藏 0 点赞 0 评论 0
public static void writeCompany(File output, Company c)
throws  JAXBException,
        FileNotFoundException,
        XMLStreamException 
{
    initializeJaxbContext();
    OutputStream os = new FileOutputStream(output);
    Marshaller marshaller = jaxbContext.createMarshaller();
    XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
       XMLStreamWriter writer = outputFactory.createXMLStreamWriter(os);
    marshaller.marshal(c, writer); // TODO: need a stream writer that does indentation      
}
Serialization.java 文件源码 项目:DocIT 阅读 21 收藏 0 点赞 0 评论 0
public static void serializeCompany(File output, Company c)
throws  JAXBException,
        FileNotFoundException,
        XMLStreamException 
{
    initializeJaxbContext();
    OutputStream os = new FileOutputStream(output);
    Marshaller marshaller = jaxbContext.createMarshaller();
    XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
       XMLStreamWriter writer = outputFactory.createXMLStreamWriter(os);
    marshaller.marshal(c, writer); // TODO: need a stream writer that does indentation      
}


问题


面经


文章

微信
公众号

扫码关注公众号