BUG-2459: Reuse SAXTransformerFactory in EXI decoder 06/13306/13
authorRobert Varga <rovarga@cisco.com>
Tue, 2 Dec 2014 13:19:49 +0000 (14:19 +0100)
committerTony Tkacik <ttkacik@cisco.com>
Mon, 8 Dec 2014 09:03:40 +0000 (09:03 +0000)
Rather than allocating the same factory over and over, create a single
instance for reuse.

Change-Id: Ia615dbd462527addadb03a5f2e54618438fb1612
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/NetconfEXIToMessageDecoder.java

index 0d8f9ee..77d33e1 100644 (file)
@@ -17,7 +17,6 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.util.List;
 import javax.xml.transform.TransformerConfigurationException;
-import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.dom.DOMResult;
 import javax.xml.transform.sax.SAXTransformerFactory;
 import javax.xml.transform.sax.TransformerHandler;
@@ -33,6 +32,7 @@ import org.xml.sax.SAXException;
 public final class NetconfEXIToMessageDecoder extends ByteToMessageDecoder {
 
     private static final Logger LOG = LoggerFactory.getLogger(NetconfEXIToMessageDecoder.class);
+    private static final SAXTransformerFactory FACTORY = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
 
     private final NetconfEXICodec codec;
 
@@ -60,10 +60,7 @@ public final class NetconfEXIToMessageDecoder extends ByteToMessageDecoder {
         }
 
         final EXIReader r = codec.getReader();
-
-        final SAXTransformerFactory transformerFactory
-            = (SAXTransformerFactory) TransformerFactory.newInstance();
-        final TransformerHandler handler = transformerFactory.newTransformerHandler();
+        final TransformerHandler handler = FACTORY.newTransformerHandler();
         r.setContentHandler(handler);
 
         final DOMResult domResult = new DOMResult();