private static NormalizedNodeDataInput streamReader(DataInput in) throws IOException { NormalizedNodeDataInput streamReader = REUSABLE_READER_TL.get(); if (streamReader == null) { streamReader = NormalizedNodeInputOutput.newDataInput(in); } return streamReader; }
@Override public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { super.readExternal(in); if (in.readBoolean()) { data = Optional.of(NormalizedNodeInputOutput.newDataInput(in).readNormalizedNode()); } else { data = Optional.absent(); } }
@Override public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { super.readExternal(in); if (in.readBoolean()) { data = Optional.of(NormalizedNodeInputOutput.newDataInput(in).readNormalizedNode()); } else { data = Optional.empty(); } }
@Override public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { super.readExternal(in); protocol = Optional.ofNullable(PersistenceProtocol.readFrom(in)); final int size = in.readInt(); if (size != 0) { modifications = new ArrayList<>(size); final NormalizedNodeDataInput nnin = NormalizedNodeInputOutput.newDataInput(in); for (int i = 0; i < size; ++i) { modifications.add(TransactionModification.readFrom(nnin)); } } else { modifications = ImmutableList.of(); } }
@Override public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { super.readExternal(in); protocol = Optional.ofNullable(PersistenceProtocol.readFrom(in)); final int size = in.readInt(); if (size != 0) { modifications = new ArrayList<>(size); final NormalizedNodeDataInput nnin = NormalizedNodeInputOutput.newDataInput(in); for (int i = 0; i < size; ++i) { modifications.add(TransactionModification.readFrom(nnin)); } } else { modifications = ImmutableList.of(); } }
@Override public final void readExternal(final ObjectInput in) throws ClassNotFoundException, IOException { super.readExternal(in); path = NormalizedNodeInputOutput.newDataInput(in).readYangInstanceIdentifier(); }
@Override public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { final NormalizedNodeDataInput dataInput = NormalizedNodeInputOutput.newDataInput(in); identifier = dataInput.readYangInstanceIdentifier(); node = dataInput.readNormalizedNode(); } }
@Override public final void readExternal(final ObjectInput in) throws ClassNotFoundException, IOException { super.readExternal(in); path = NormalizedNodeInputOutput.newDataInput(in).readYangInstanceIdentifier(); }
private void readObject(final ObjectInputStream stream) throws IOException { NormalizedNodeDataInput reader = NormalizedNodeInputOutput.newDataInput(stream); this.input = reader.readNormalizedNode(); }
@Override public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { rpcInvoker = JavaSerializer.currentSystem().value().provider().resolveActorRef((String) in.readObject()); final NormalizedNodeDataInput nnin = NormalizedNodeInputOutput.newDataInput(in); final int size = nnin.readInt(); rpcs = new ArrayList<>(size); for (int i = 0; i < size; ++i) { rpcs.add(DOMRpcIdentifier.create(nnin.readSchemaPath(), nnin.readYangInstanceIdentifier())); } }
@Test(expected = InvalidNormalizedNodeStreamException.class, timeout = 10000) public void testInvalidNormalizedNodeStream() throws IOException { byte[] invalidBytes = {1,2,3}; NormalizedNodeDataInput reader = NormalizedNodeInputOutput.newDataInput( ByteStreams.newDataInput(invalidBytes)); reader.readNormalizedNode(); }
@Test(expected = InvalidNormalizedNodeStreamException.class, timeout = 10000) public void testInvalidYangInstanceIdentifierStream() throws IOException { byte[] invalidBytes = {1,2,3}; NormalizedNodeDataInput reader = NormalizedNodeInputOutput.newDataInput( ByteStreams.newDataInput(invalidBytes)); reader.readYangInstanceIdentifier(); }
@Test public void testSchemaPathSerialization() throws Exception { final SchemaPath expected = SchemaPath.create(true, TestModel.ANY_XML_QNAME); ByteArrayOutputStream bos = new ByteArrayOutputStream(); NormalizedNodeDataOutput nnout = NormalizedNodeInputOutput.newDataOutput(ByteStreams.newDataOutput(bos)); nnout.writeSchemaPath(expected); NormalizedNodeDataInput nnin = NormalizedNodeInputOutput.newDataInput(ByteStreams.newDataInput( bos.toByteArray())); SchemaPath actual = nnin.readSchemaPath(); assertEquals(expected, actual); }
@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()); }
@Test public void testYangInstanceIdentifierStreaming() throws IOException { YangInstanceIdentifier path = YangInstanceIdentifier.builder(TestModel.TEST_PATH) .node(TestModel.OUTER_LIST_QNAME).nodeWithKey( TestModel.INNER_LIST_QNAME, TestModel.ID_QNAME, 10).build(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); NormalizedNodeDataOutput nnout = NormalizedNodeInputOutput.newDataOutput(ByteStreams.newDataOutput(bos)); nnout.writeYangInstanceIdentifier(path); NormalizedNodeDataInput nnin = NormalizedNodeInputOutput.newDataInput(ByteStreams.newDataInput( bos.toByteArray())); YangInstanceIdentifier newPath = nnin.readYangInstanceIdentifier(); Assert.assertEquals(path, newPath); }
@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); }
@Test public void testNormalizedNodeAndYangInstanceIdentifierStreaming() throws IOException { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); NormalizedNodeOutputStreamWriter writer = new NormalizedNodeOutputStreamWriter( ByteStreams.newDataOutput(byteArrayOutputStream)); NormalizedNode<?, ?> testContainer = TestModel.createBaseTestContainerBuilder().build(); writer.writeNormalizedNode(testContainer); YangInstanceIdentifier path = YangInstanceIdentifier.builder(TestModel.TEST_PATH) .node(TestModel.OUTER_LIST_QNAME).nodeWithKey( TestModel.INNER_LIST_QNAME, TestModel.ID_QNAME, 10).build(); writer.writeYangInstanceIdentifier(path); NormalizedNodeDataInput reader = NormalizedNodeInputOutput.newDataInput( ByteStreams.newDataInput(byteArrayOutputStream.toByteArray())); NormalizedNode<?,?> node = reader.readNormalizedNode(); Assert.assertEquals(testContainer, node); YangInstanceIdentifier newPath = reader.readYangInstanceIdentifier(); Assert.assertEquals(path, newPath); writer.close(); }