You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by bu...@apache.org on 2021/02/22 13:37:04 UTC

[cxf] branch master updated: cxf-core: use StaxUtils.writeTo (#750)

This is an automated email from the ASF dual-hosted git repository.

buhhunyx pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/master by this push:
     new 2ad6045  cxf-core: use StaxUtils.writeTo (#750)
2ad6045 is described below

commit 2ad604591d0d2c03ad6d961b052198ca821a139c
Author: Alexey Markevich <bu...@gmail.com>
AuthorDate: Mon Feb 22 13:36:50 2021 +0000

    cxf-core: use StaxUtils.writeTo (#750)
---
 .../blueprint/AbstractBPBeanDefinitionParser.java       | 10 ++--------
 .../spring/AbstractBeanDefinitionParser.java            | 17 ++++-------------
 2 files changed, 6 insertions(+), 21 deletions(-)

diff --git a/core/src/main/java/org/apache/cxf/configuration/blueprint/AbstractBPBeanDefinitionParser.java b/core/src/main/java/org/apache/cxf/configuration/blueprint/AbstractBPBeanDefinitionParser.java
index 7e4f39c..c32f40c 100644
--- a/core/src/main/java/org/apache/cxf/configuration/blueprint/AbstractBPBeanDefinitionParser.java
+++ b/core/src/main/java/org/apache/cxf/configuration/blueprint/AbstractBPBeanDefinitionParser.java
@@ -31,7 +31,6 @@ import javax.xml.bind.Unmarshaller;
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
-import javax.xml.stream.XMLStreamWriter;
 
 import org.w3c.dom.Attr;
 import org.w3c.dom.Element;
@@ -358,14 +357,10 @@ public abstract class AbstractBPBeanDefinitionParser {
                                             String propertyName,
                                             Class<?> c) {
         try {
-            XMLStreamWriter xmlWriter = null;
             Unmarshaller u = null;
             try {
-                StringWriter writer = new StringWriter();
-                xmlWriter = StaxUtils.createXMLStreamWriter(writer);
-                StaxUtils.copy(data, xmlWriter);
-                xmlWriter.flush();
-
+                final StringWriter writer = new StringWriter();
+                StaxUtils.writeTo(data, writer);
 
                 MutableBeanMetadata factory = ctx.createMetadata(MutableBeanMetadata.class);
                 factory.setClassName(c.getName());
@@ -393,7 +388,6 @@ public abstract class AbstractBPBeanDefinitionParser {
                     bean.addProperty(propertyName, value);
                 }
             } finally {
-                StaxUtils.close(xmlWriter);
                 JAXBUtils.closeUnmarshaller(u);
             }
         } catch (JAXBException e) {
diff --git a/core/src/main/java/org/apache/cxf/configuration/spring/AbstractBeanDefinitionParser.java b/core/src/main/java/org/apache/cxf/configuration/spring/AbstractBeanDefinitionParser.java
index 4fc5921..5cce4a9 100644
--- a/core/src/main/java/org/apache/cxf/configuration/spring/AbstractBeanDefinitionParser.java
+++ b/core/src/main/java/org/apache/cxf/configuration/spring/AbstractBeanDefinitionParser.java
@@ -32,7 +32,6 @@ import javax.xml.bind.Unmarshaller;
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
-import javax.xml.stream.XMLStreamWriter;
 
 import org.w3c.dom.Attr;
 import org.w3c.dom.Element;
@@ -337,13 +336,10 @@ public abstract class AbstractBeanDefinitionParser
                                             String propertyName,
                                             Class<?> c) {
         try {
-            XMLStreamWriter xmlWriter = null;
             Unmarshaller u = null;
             try {
-                StringWriter writer = new StringWriter();
-                xmlWriter = StaxUtils.createXMLStreamWriter(writer);
-                StaxUtils.copy(data, xmlWriter);
-                xmlWriter.flush();
+                final StringWriter writer = new StringWriter();
+                StaxUtils.writeTo(data, writer);
 
                 BeanDefinitionBuilder jaxbbean
                     = BeanDefinitionBuilder.rootBeanDefinition(JAXBBeanFactory.class);
@@ -369,7 +365,6 @@ public abstract class AbstractBeanDefinitionParser
                     bean.addPropertyValue(propertyName, obj);
                 }
             } finally {
-                StaxUtils.close(xmlWriter);
                 JAXBUtils.closeUnmarshaller(u);
             }
         } catch (JAXBException e) {
@@ -403,15 +398,11 @@ public abstract class AbstractBeanDefinitionParser
                                                       Class<?> jaxbClass,
                                                       String method,
                                                       Object ... args) {
-        StringWriter writer = new StringWriter();
-        XMLStreamWriter xmlWriter = StaxUtils.createXMLStreamWriter(writer);
+        final StringWriter writer = new StringWriter();
         try {
-            StaxUtils.copy(data, xmlWriter);
-            xmlWriter.flush();
+            StaxUtils.writeTo(data, writer);
         } catch (XMLStreamException e) {
             throw new RuntimeException(e);
-        } finally {
-            StaxUtils.close(xmlWriter);
         }
 
         BeanDefinitionBuilder jaxbbean