public static void serializeNormalizedNode(NormalizedNode<?, ?> node, DataOutput out) { try { out.writeBoolean(node != null); if(node != null) { NormalizedNodeDataOutput streamWriter = streamWriter(out); streamWriter.writeNormalizedNode(node); } } catch (IOException e) { throw new IllegalArgumentException(String.format("Error serializing NormalizedNode %s", node), e); } }
public static void serializeNormalizedNode(NormalizedNode<?, ?> node, DataOutput out) { try { out.writeBoolean(node != null); if (node != null) { NormalizedNodeDataOutput streamWriter = streamWriter(out); streamWriter.writeNormalizedNode(node); } } catch (IOException e) { throw new IllegalArgumentException(String.format("Error serializing NormalizedNode %s", node), e); } }
@Override final void writeTo(final NormalizedNodeDataOutput out) throws IOException { super.writeTo(out); out.writeNormalizedNode(data); } }
@Override final void writeTo(final NormalizedNodeDataOutput out) throws IOException { super.writeTo(out); out.writeNormalizedNode(data); } }
@Override public void writeExternal(final ObjectOutput out) throws IOException { super.writeExternal(out); if (data.isPresent()) { out.writeBoolean(true); try (NormalizedNodeDataOutput nnout = NormalizedNodeInputOutput.newDataOutput(out)) { nnout.writeNormalizedNode(data.get()); } } else { out.writeBoolean(false); } }
public static void serializePathAndNode(YangInstanceIdentifier path, NormalizedNode<?, ?> node, DataOutput out) { Preconditions.checkNotNull(path); Preconditions.checkNotNull(node); try { NormalizedNodeDataOutput streamWriter = streamWriter(out); streamWriter.writeNormalizedNode(node); streamWriter.writeYangInstanceIdentifier(path); } catch (IOException e) { throw new IllegalArgumentException(String.format("Error serializing path %s and Node %s", path, node), e); } }
@Override public void writeExternal(final ObjectOutput out) throws IOException { super.writeExternal(out); if (data.isPresent()) { out.writeBoolean(true); try (NormalizedNodeDataOutput nnout = NormalizedNodeInputOutput.newDataOutput(out)) { nnout.writeNormalizedNode(data.get()); } } else { out.writeBoolean(false); } out.writeObject(data); }
public static void serializePathAndNode(YangInstanceIdentifier path, NormalizedNode<?, ?> node, DataOutput out) { Preconditions.checkNotNull(path); Preconditions.checkNotNull(node); try { NormalizedNodeDataOutput streamWriter = streamWriter(out); streamWriter.writeNormalizedNode(node); streamWriter.writeYangInstanceIdentifier(path); } catch (IOException e) { throw new IllegalArgumentException(String.format("Error serializing path %s and Node %s", path, node), e); } }
for(Map.Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> e: createdData.entrySet()) { streamWriter.writeYangInstanceIdentifier(e.getKey()); streamWriter.writeNormalizedNode(e.getValue()); for(Map.Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> e: updatedData.entrySet()) { streamWriter.writeYangInstanceIdentifier(e.getKey()); streamWriter.writeNormalizedNode(originalData.get(e.getKey())); streamWriter.writeNormalizedNode(e.getValue()); for(YangInstanceIdentifier path: removed) { streamWriter.writeYangInstanceIdentifier(path); streamWriter.writeNormalizedNode(originalData.get(path)); out.writeBoolean(originalSubtree != null); if(originalSubtree != null) { streamWriter.writeNormalizedNode(originalSubtree); out.writeBoolean(updatedSubtree != null); if(updatedSubtree != null) { streamWriter.writeNormalizedNode(updatedSubtree);
@Test public void testAnyXmlStreaming() throws Exception { String xml = "<foo xmlns=\"http://www.w3.org/TR/html4/\" x=\"123\"><bar>one</bar><bar>two</bar></foo>"; final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); Node xmlNode = factory.newDocumentBuilder().parse( new InputSource(new StringReader(xml))).getDocumentElement(); assertEquals("http://www.w3.org/TR/html4/", xmlNode.getNamespaceURI()); NormalizedNode<?, ?> anyXmlContainer = ImmutableContainerNodeBuilder.create().withNodeIdentifier( new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)).withChild( Builders.anyXmlBuilder().withNodeIdentifier(new NodeIdentifier(TestModel.ANY_XML_QNAME)) .withValue(new DOMSource(xmlNode)).build()).build(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); NormalizedNodeDataOutput nnout = NormalizedNodeInputOutput.newDataOutput(ByteStreams.newDataOutput(bos)); nnout.writeNormalizedNode(anyXmlContainer); NormalizedNodeDataInput nnin = NormalizedNodeInputOutput.newDataInput(ByteStreams.newDataInput( bos.toByteArray())); ContainerNode deserialized = (ContainerNode)nnin.readNormalizedNode(); Optional<DataContainerChild<? extends PathArgument, ?>> child = deserialized.getChild(new NodeIdentifier(TestModel.ANY_XML_QNAME)); assertEquals("AnyXml child present", true, child.isPresent()); StreamResult xmlOutput = new StreamResult(new StringWriter()); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.transform(((AnyXmlNode)child.get()).getValue(), xmlOutput); assertEquals("XML", xml, xmlOutput.getWriter().toString()); assertEquals("http://www.w3.org/TR/html4/", ((AnyXmlNode)child.get()).getValue().getNode().getNamespaceURI()); }
case WRITE: writer.writeByte(WRITE); writer.writeNormalizedNode(node.getDataAfter().get()); break; default:
@Test public void testNormalizedNodeStreaming() throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); NormalizedNodeDataOutput nnout = NormalizedNodeInputOutput.newDataOutput(ByteStreams.newDataOutput(bos)); NormalizedNode<?, ?> testContainer = createTestContainer(); nnout.writeNormalizedNode(testContainer); QName toaster = QName.create("http://netconfcentral.org/ns/toaster","2009-11-20","toaster"); QName darknessFactor = QName.create("http://netconfcentral.org/ns/toaster","2009-11-20","darknessFactor"); QName description = QName.create("http://netconfcentral.org/ns/toaster","2009-11-20","description"); ContainerNode toasterNode = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(toaster)) .withChild(ImmutableNodes.leafNode(darknessFactor, "1000")) .withChild(ImmutableNodes.leafNode(description, largeString(20))).build(); ContainerNode toasterContainer = Builders.containerBuilder() .withNodeIdentifier(new NodeIdentifier(SchemaContext.NAME)).withChild(toasterNode).build(); nnout.writeNormalizedNode(toasterContainer); NormalizedNodeDataInput nnin = NormalizedNodeInputOutput.newDataInput(ByteStreams.newDataInput( bos.toByteArray())); NormalizedNode<?,?> node = nnin.readNormalizedNode(); Assert.assertEquals(testContainer, node); node = nnin.readNormalizedNode(); Assert.assertEquals(toasterContainer, node); }
case WRITE: out.writeByte(WRITE); out.writeNormalizedNode(node.getDataAfter().get()); break; case UNMODIFIED: