- private NormalizedNodeWriter normalizedNodeWriter;
-
- private boolean wroteSignatureMarker;
-
- public NormalizedNodeOutputStreamWriter(OutputStream stream) throws IOException {
- Preconditions.checkNotNull(stream);
- output = new DataOutputStream(stream);
- }
-
- public NormalizedNodeOutputStreamWriter(DataOutput output) throws IOException {
- this.output = Preconditions.checkNotNull(output);
- }
-
- private NormalizedNodeWriter normalizedNodeWriter() {
- if(normalizedNodeWriter == null) {
- normalizedNodeWriter = NormalizedNodeWriter.forStreamWriter(this);
- }
-
- return normalizedNodeWriter;
- }
-
- public void writeNormalizedNode(NormalizedNode<?, ?> node) throws IOException {
- writeSignatureMarkerAndVersionIfNeeded();
- normalizedNodeWriter().write(node);
- }
-
- private void writeSignatureMarkerAndVersionIfNeeded() throws IOException {
- if(!wroteSignatureMarker) {
- output.writeByte(SIGNATURE_MARKER);
- output.writeShort(CURRENT_VERSION);
- wroteSignatureMarker = true;
- }
- }
-
- @Override
- public void leafNode(YangInstanceIdentifier.NodeIdentifier name, Object value) throws IOException, IllegalArgumentException {
- Preconditions.checkNotNull(name, "Node identifier should not be null");
- LOG.debug("Writing a new leaf node");
- startNode(name.getNodeType(), NodeTypes.LEAF_NODE);
-
- writeObject(value);
- }
-
- @Override
- public void startLeafSet(YangInstanceIdentifier.NodeIdentifier name, int childSizeHint) throws IOException, IllegalArgumentException {
- Preconditions.checkNotNull(name, "Node identifier should not be null");
- LOG.debug("Starting a new leaf set");
-
- startNode(name.getNodeType(), NodeTypes.LEAF_SET);
- }
-
- @Override
- public void leafSetEntryNode(Object value) throws IOException, IllegalArgumentException {
- LOG.debug("Writing a new leaf set entry node");
-
- output.writeByte(NodeTypes.LEAF_SET_ENTRY_NODE);
- writeObject(value);
- }
-
- @Override
- public void startContainerNode(YangInstanceIdentifier.NodeIdentifier name, int childSizeHint) throws IOException, IllegalArgumentException {
- Preconditions.checkNotNull(name, "Node identifier should not be null");
-
- LOG.debug("Starting a new container node");
-
- startNode(name.getNodeType(), NodeTypes.CONTAINER_NODE);
- }
-
- @Override
- public void startUnkeyedList(YangInstanceIdentifier.NodeIdentifier name, int childSizeHint) throws IOException, IllegalArgumentException {
- Preconditions.checkNotNull(name, "Node identifier should not be null");
- LOG.debug("Starting a new unkeyed list");
-
- startNode(name.getNodeType(), NodeTypes.UNKEYED_LIST);
- }
-
- @Override
- public void startUnkeyedListItem(YangInstanceIdentifier.NodeIdentifier name, int childSizeHint) throws IOException, IllegalStateException {
- Preconditions.checkNotNull(name, "Node identifier should not be null");
- LOG.debug("Starting a new unkeyed list item");
-
- startNode(name.getNodeType(), NodeTypes.UNKEYED_LIST_ITEM);
- }
-
- @Override
- public void startMapNode(YangInstanceIdentifier.NodeIdentifier name, int childSizeHint) throws IOException, IllegalArgumentException {
- Preconditions.checkNotNull(name, "Node identifier should not be null");
- LOG.debug("Starting a new map node");
-
- startNode(name.getNodeType(), NodeTypes.MAP_NODE);
- }
-
- @Override
- public void startMapEntryNode(YangInstanceIdentifier.NodeIdentifierWithPredicates identifier, int childSizeHint) throws IOException, IllegalArgumentException {
- Preconditions.checkNotNull(identifier, "Node identifier should not be null");
- LOG.debug("Starting a new map entry node");
- startNode(identifier.getNodeType(), NodeTypes.MAP_ENTRY_NODE);
-
- writeKeyValueMap(identifier.getKeyValues());
-
- }
-
- @Override
- public void startOrderedMapNode(YangInstanceIdentifier.NodeIdentifier name, int childSizeHint) throws IOException, IllegalArgumentException {
- Preconditions.checkNotNull(name, "Node identifier should not be null");
- LOG.debug("Starting a new ordered map node");
-
- startNode(name.getNodeType(), NodeTypes.ORDERED_MAP_NODE);
- }
-
- @Override
- public void startChoiceNode(YangInstanceIdentifier.NodeIdentifier name, int childSizeHint) throws IOException, IllegalArgumentException {
- Preconditions.checkNotNull(name, "Node identifier should not be null");
- LOG.debug("Starting a new choice node");
-
- startNode(name.getNodeType(), NodeTypes.CHOICE_NODE);