Remove ensureHeaderWritten() from writeNode()
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / main / java / org / opendaylight / controller / cluster / datastore / node / utils / stream / AbstractNormalizedNodeDataOutput.java
index 099f1be6ef6c33ca3f61b6035dfa111890673ec0..111c8c71d0c3f7677ae85d1263134d792b6ecadf 100755 (executable)
@@ -38,18 +38,13 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * NormalizedNodeOutputStreamWriter will be used by distributed datastore to send normalized node in
- * a stream.
- * A stream writer wrapper around this class will write node objects to stream in recursive manner.
- * for example - If you have a ContainerNode which has a two LeafNode as children, then
- * you will first call
- * {@link #startContainerNode(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier, int)},
- * then will call
- * {@link #leafNode(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier, Object)} twice
- * and then, {@link #endNode()} to end container node.
+ * Abstract base class for implementing {@link NormalizedNodeDataOutput} contract. This class uses
+ * {@link NormalizedNodeStreamWriter} as an internal interface for performing the actual NormalizedNode writeout,
+ * i.e. it will defer to a {@link NormalizedNodeWriter} instance.
  *
- * <p>Based on the each node, the node type is also written to the stream, that helps in reconstructing the object,
- * while reading.
+ * <p>
+ * As such, this is an implementation detail not exposed from this package, hence implementations can rely on the
+ * stream being initialized with a header and version.
  */
 abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOutput, NormalizedNodeStreamWriter {
     private static final Logger LOG = LoggerFactory.getLogger(AbstractNormalizedNodeDataOutput.class);
@@ -64,6 +59,10 @@ abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOut
         this.output = Preconditions.checkNotNull(output);
     }
 
+    final DataOutput output() {
+        return output;
+    }
+
     private void ensureHeaderWritten() throws IOException {
         if (!headerWritten) {
             output.writeByte(TokenTypes.SIGNATURE_MARKER);
@@ -358,8 +357,6 @@ abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOut
     private void startNode(final QName qname, final byte nodeType) throws IOException {
         Preconditions.checkNotNull(qname, "QName of node identifier should not be null.");
 
-        ensureHeaderWritten();
-
         // First write the type of node
         output.writeByte(nodeType);
         // Write Start Tag