Automatic addition of final keywords
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / main / java / org / opendaylight / controller / cluster / datastore / node / utils / stream / NormalizedNodeInputStreamReader.java
index bb2f5d41d920d5ce97c723fe6bc91cafc5cd6031..cea8fad4ea15d57bc57a4e3e8d1da820e2dab17f 100644 (file)
@@ -1,11 +1,9 @@
 /*
+ * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others.  All rights reserved.
  *
- *  Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
- *
- *  This program and the accompanying materials are made available under the
- *  terms of the Eclipse Public License v1.0 which accompanies this distribution,
- *  and is available at http://www.eclipse.org/legal/epl-v10.html
- *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
 
 package org.opendaylight.controller.cluster.datastore.node.utils.stream;
@@ -18,15 +16,16 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.math.BigDecimal;
 import java.math.BigInteger;
+import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import javax.xml.transform.dom.DOMSource;
 import org.opendaylight.controller.cluster.datastore.node.utils.QNameFactory;
 import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.Node;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
@@ -71,12 +70,12 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeStreamRead
 
     private boolean readSignatureMarker = true;
 
-    public NormalizedNodeInputStreamReader(InputStream stream) throws IOException {
+    public NormalizedNodeInputStreamReader(final InputStream stream) throws IOException {
         Preconditions.checkNotNull(stream);
         input = new DataInputStream(stream);
     }
 
-    public NormalizedNodeInputStreamReader(DataInput input) throws IOException {
+    public NormalizedNodeInputStreamReader(final DataInput input) {
         this.input = Preconditions.checkNotNull(input);
     }
 
@@ -159,7 +158,7 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeStreamRead
         return leafSetEntryBuilder;
     }
 
-    private NormalizedNode<?, ?> readNodeIdentifierDependentNode(byte nodeType, NodeIdentifier identifier)
+    private NormalizedNode<?, ?> readNodeIdentifierDependentNode(final byte nodeType, final NodeIdentifier identifier)
         throws IOException {
 
         switch(nodeType) {
@@ -170,7 +169,7 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeStreamRead
 
             case NodeTypes.ANY_XML_NODE :
                 LOG.debug("Read xml node");
-                return Builders.anyXmlBuilder().withValue((Node<?>) readObject()).build();
+                return Builders.anyXmlBuilder().withValue((DOMSource) readObject()).build();
 
             case NodeTypes.MAP_NODE :
                 LOG.debug("Read map node {}", identifier);
@@ -293,6 +292,9 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeStreamRead
             case ValueTypes.STRING_TYPE :
                 return input.readUTF();
 
+            case ValueTypes.STRING_BYTES_TYPE:
+                return readStringBytes();
+
             case ValueTypes.BIG_DECIMAL_TYPE :
                 return new BigDecimal(input.readUTF());
 
@@ -312,6 +314,12 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeStreamRead
         }
     }
 
+    private String readStringBytes() throws IOException {
+        byte[] bytes = new byte[input.readInt()];
+        input.readFully(bytes);
+        return new String(bytes, StandardCharsets.UTF_8);
+    }
+
     public YangInstanceIdentifier readYangInstanceIdentifier() throws IOException {
         readSignatureMarkerAndVersionIfNeeded();
         return readYangInstanceIdentifierInternal();
@@ -337,7 +345,7 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeStreamRead
         return children;
     }
 
-    private PathArgument readPathArgument() throws IOException {
+    public PathArgument readPathArgument() throws IOException {
         // read Type
         int type = input.readByte();
 
@@ -361,8 +369,8 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeStreamRead
     }
 
     @SuppressWarnings("unchecked")
-    private ListNodeBuilder<Object, LeafSetEntryNode<Object>> addLeafSetChildren(QName nodeType,
-            ListNodeBuilder<Object, LeafSetEntryNode<Object>> builder) throws IOException {
+    private ListNodeBuilder<Object, LeafSetEntryNode<Object>> addLeafSetChildren(final QName nodeType,
+            final ListNodeBuilder<Object, LeafSetEntryNode<Object>> builder) throws IOException {
 
         LOG.debug("Reading children of leaf set");
 
@@ -379,7 +387,7 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeStreamRead
 
     @SuppressWarnings({ "unchecked", "rawtypes" })
     private NormalizedNodeContainerBuilder addDataContainerChildren(
-            NormalizedNodeContainerBuilder builder) throws IOException {
+            final NormalizedNodeContainerBuilder builder) throws IOException {
         LOG.debug("Reading data container (leaf nodes) nodes");
 
         NormalizedNode<?, ?> child = readNormalizedNodeInternal();