/** * Creates a new {@link NormalizedNodeDataInput} instance that reads from the given input. This method does not * perform any initial validation of the input stream. * * @param input the DataInput to read from * @return a new {@link NormalizedNodeDataInput} instance */ public static NormalizedNodeDataInput newDataInputWithoutValidation(@Nonnull final DataInput input) { return new NormalizedNodeInputStreamReader(input, false); }
private Set<String> readObjSet() throws IOException { int count = input.readInt(); Set<String> children = new HashSet<>(count); for(int i = 0; i < count; i++) { children.add(readCodedString()); } return children; }
@Override public PathArgument readPathArgument() throws IOException { // read Type int type = input.readByte(); switch(type) { case PathArgumentTypes.AUGMENTATION_IDENTIFIER : return new YangInstanceIdentifier.AugmentationIdentifier(readQNameSet()); case PathArgumentTypes.NODE_IDENTIFIER : return new NodeIdentifier(readQName()); case PathArgumentTypes.NODE_IDENTIFIER_WITH_PREDICATES : return new NodeIdentifierWithPredicates(readQName(), readKeyValueMap()); case PathArgumentTypes.NODE_IDENTIFIER_WITH_VALUE : return new NodeWithValue<>(readQName(), readObject()); default : return null; } }
@Override public NormalizedNode<?, ?> readNormalizedNode() throws IOException { readSignatureMarkerAndVersionIfNeeded(); return readNormalizedNodeInternal(); }
case NodeTypes.AUGMENTATION_NODE : YangInstanceIdentifier.AugmentationIdentifier augIdentifier = new YangInstanceIdentifier.AugmentationIdentifier(readQNameSet()); return addDataContainerChildren(Builders.augmentationBuilder(). withNodeIdentifier(augIdentifier)).build(); QName name = lastLeafSetQName; if(name == null) { name = readQName(); Object value = readObject(); NodeWithValue<Object> leafIdentifier = new NodeWithValue<>(name, value); return leafSetEntryBuilder().withNodeIdentifier(leafIdentifier).withValue(value).build(); readQName(), readKeyValueMap()); return addDataContainerChildren(Builders.mapEntryBuilder(). withNodeIdentifier(entryIdentifier)).build(); return readNodeIdentifierDependentNode(nodeType, new NodeIdentifier(readQName()));
case NodeTypes.AUGMENTATION_NODE : YangInstanceIdentifier.AugmentationIdentifier augIdentifier = new YangInstanceIdentifier.AugmentationIdentifier(readQNameSet()); return addDataContainerChildren(Builders.augmentationBuilder() .withNodeIdentifier(augIdentifier)).build(); QName name = lastLeafSetQName; if (name == null) { name = readQName(); Object value = readObject(); NodeWithValue<Object> leafIdentifier = new NodeWithValue<>(name, value); return leafSetEntryBuilder().withNodeIdentifier(leafIdentifier).withValue(value).build(); NodeIdentifierWithPredicates entryIdentifier = readNormalizedNodeWithPredicates(); return addDataContainerChildren(Builders.mapEntryBuilder() .withNodeIdentifier(entryIdentifier)).build(); return readNodeIdentifierDependentNode(nodeType, new NodeIdentifier(readQName()));
LOG.trace("Read leaf node {}", identifier); return leafBuilder().withNodeIdentifier(identifier).withValue(readObject()).build(); return Builders.anyXmlBuilder().withNodeIdentifier(identifier).withValue(readDOMSource()).build(); return addDataContainerChildren(Builders.mapBuilder().withNodeIdentifier(identifier)).build(); return addDataContainerChildren(Builders.choiceBuilder().withNodeIdentifier(identifier)).build(); return addDataContainerChildren(Builders.orderedMapBuilder().withNodeIdentifier(identifier)).build(); return addDataContainerChildren(Builders.unkeyedListBuilder().withNodeIdentifier(identifier)).build(); return addDataContainerChildren(Builders.unkeyedListEntryBuilder() .withNodeIdentifier(identifier)).build(); return addDataContainerChildren(Builders.containerBuilder().withNodeIdentifier(identifier)).build(); return addLeafSetChildren(identifier.getNodeType(), Builders.leafSetBuilder().withNodeIdentifier(identifier)).build(); return addLeafSetChildren(identifier.getNodeType(), Builders.orderedLeafSetBuilder().withNodeIdentifier(identifier)).build();
@SuppressWarnings("unchecked") private ListNodeBuilder<Object, LeafSetEntryNode<Object>> addLeafSetChildren(final QName nodeType, final ListNodeBuilder<Object, LeafSetEntryNode<Object>> builder) throws IOException { LOG.trace("Reading children of leaf set"); lastLeafSetQName = nodeType; LeafSetEntryNode<Object> child = (LeafSetEntryNode<Object>)readNormalizedNodeInternal(); while (child != null) { builder.withChild(child); child = (LeafSetEntryNode<Object>)readNormalizedNodeInternal(); } return builder; }
return leafBuilder().withNodeIdentifier(identifier).withValue(readObject()).build(); return Builders.anyXmlBuilder().withValue((DOMSource) readObject()).build(); return addDataContainerChildren(Builders.mapBuilder(). withNodeIdentifier(identifier)).build(); return addDataContainerChildren(Builders.choiceBuilder(). withNodeIdentifier(identifier)).build(); return addDataContainerChildren(Builders.orderedMapBuilder(). withNodeIdentifier(identifier)).build(); return addDataContainerChildren(Builders.unkeyedListBuilder(). withNodeIdentifier(identifier)).build(); return addDataContainerChildren(Builders.unkeyedListEntryBuilder(). withNodeIdentifier(identifier)).build(); return addDataContainerChildren(Builders.containerBuilder(). withNodeIdentifier(identifier)).build(); return addLeafSetChildren(identifier.getNodeType(), Builders.leafSetBuilder().withNodeIdentifier(identifier)).build(); ListNodeBuilder<Object, LeafSetEntryNode<Object>> orderedLeafSetBuilder = Builders.orderedLeafSetBuilder().withNodeIdentifier(identifier); orderedLeafSetBuilder = addLeafSetChildren(identifier.getNodeType(), orderedLeafSetBuilder); return orderedLeafSetBuilder.build();
@Override public NormalizedNode<?, ?> readNormalizedNode() throws IOException { readSignatureMarkerAndVersionIfNeeded(); return readNormalizedNodeInternal(); }
@SuppressWarnings("unchecked") private ListNodeBuilder<Object, LeafSetEntryNode<Object>> addLeafSetChildren(final QName nodeType, final ListNodeBuilder<Object, LeafSetEntryNode<Object>> builder) throws IOException { LOG.debug("Reading children of leaf set"); lastLeafSetQName = nodeType; LeafSetEntryNode<Object> child = (LeafSetEntryNode<Object>)readNormalizedNodeInternal(); while(child != null) { builder.withChild(child); child = (LeafSetEntryNode<Object>)readNormalizedNodeInternal(); } return builder; }
private static NormalizedNodeDataInput streamReader(DataInput in) throws IOException { NormalizedNodeDataInput streamReader = REUSABLE_READER_TL.get(); if(streamReader == null) { streamReader = new NormalizedNodeInputStreamReader(in); } return streamReader; }
@SuppressWarnings({ "unchecked", "rawtypes" }) private NormalizedNodeContainerBuilder addDataContainerChildren( final NormalizedNodeContainerBuilder builder) throws IOException { LOG.debug("Reading data container (leaf nodes) nodes"); NormalizedNode<?, ?> child = readNormalizedNodeInternal(); while(child != null) { builder.addChild(child); child = readNormalizedNodeInternal(); } return builder; }
private Set<String> readObjSet() throws IOException { int count = input.readInt(); Set<String> children = new HashSet<>(count); for (int i = 0; i < count; i++) { children.add(readCodedString()); } return children; }
public static NormalizedNodeDataInput newDataInput(@Nonnull final DataInput input) throws IOException { final byte marker = input.readByte(); if (marker != TokenTypes.SIGNATURE_MARKER) { throw new InvalidNormalizedNodeStreamException(String.format("Invalid signature marker: %d", marker)); } final short version = input.readShort(); switch (version) { case TokenTypes.LITHIUM_VERSION: return new NormalizedNodeInputStreamReader(input, true); default: throw new InvalidNormalizedNodeStreamException(String.format("Unhandled stream version %s", version)); } }
@SuppressWarnings({ "unchecked", "rawtypes" }) private NormalizedNodeContainerBuilder addDataContainerChildren( final NormalizedNodeContainerBuilder builder) throws IOException { LOG.trace("Reading data container (leaf nodes) nodes"); NormalizedNode<?, ?> child = readNormalizedNodeInternal(); while (child != null) { builder.addChild(child); child = readNormalizedNodeInternal(); } return builder; }
private QName readQName() throws IOException { // Read in the same sequence of writing String localName = readCodedString(); String namespace = readCodedString(); String revision = readCodedString(); String qname; if (!Strings.isNullOrEmpty(revision)) { qname = reusableStringBuilder.append('(').append(namespace).append(REVISION_ARG).append(revision) .append(')').append(localName).toString(); } else { qname = reusableStringBuilder.append('(').append(namespace).append(')').append(localName).toString(); } reusableStringBuilder.delete(0, reusableStringBuilder.length()); return QNameFactory.create(qname); }
/** * Creates a new {@link NormalizedNodeDataInput} instance that reads from the given input. This method first reads * and validates that the input contains a valid NormalizedNode stream. * * @param input the DataInput to read from * @return a new {@link NormalizedNodeDataInput} instance * @throws IOException if an error occurs reading from the input */ public static NormalizedNodeDataInput newDataInput(@Nonnull final DataInput input) throws IOException { final byte marker = input.readByte(); if (marker != TokenTypes.SIGNATURE_MARKER) { throw new InvalidNormalizedNodeStreamException(String.format("Invalid signature marker: %d", marker)); } final short version = input.readShort(); switch (version) { case TokenTypes.LITHIUM_VERSION: return new NormalizedNodeInputStreamReader(input, true); default: throw new InvalidNormalizedNodeStreamException(String.format("Unhandled stream version %s", version)); } }
private QName readQName() throws IOException { // Read in the same sequence of writing String localName = readCodedString(); String namespace = readCodedString(); String revision = readCodedString(); String qName; if(!Strings.isNullOrEmpty(revision)) { qName = reusableStringBuilder.append('(').append(namespace).append(REVISION_ARG). append(revision).append(')').append(localName).toString(); } else { qName = reusableStringBuilder.append('(').append(namespace).append(')'). append(localName).toString(); } reusableStringBuilder.delete(0, reusableStringBuilder.length()); return QNameFactory.create(qName); }
@Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { super.readExternal(in); int size = in.readInt(); if(size > 1) { SerializationUtils.REUSABLE_READER_TL.set(new NormalizedNodeInputStreamReader(in)); } try { for(int i = 0; i < size; i++) { byte type = in.readByte(); switch(type) { case Modification.WRITE: modifications.add(WriteModification.fromStream(in, getVersion())); break; case Modification.MERGE: modifications.add(MergeModification.fromStream(in, getVersion())); break; case Modification.DELETE: modifications.add(DeleteModification.fromStream(in, getVersion())); break; } } } finally { SerializationUtils.REUSABLE_READER_TL.remove(); } }