Bug 2265: Modified NormalizedNodeOutputStreamWriter to implement yangtools interface
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / test / java / org / opendaylight / controller / cluster / datastore / node / utils / stream / SampleNormalizedNodeSerializable.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.controller.cluster.datastore.node.utils.stream;
10
11
12 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
13 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter;
14 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
15
16 import java.io.IOException;
17 import java.io.ObjectInputStream;
18 import java.io.ObjectOutputStream;
19 import java.io.Serializable;
20 import java.net.URISyntaxException;
21
22 public class SampleNormalizedNodeSerializable implements Serializable {
23     private static final long serialVersionUID = 1L;
24
25     private NormalizedNode<?, ?> input;
26
27     public SampleNormalizedNodeSerializable(NormalizedNode<?, ?> input) {
28         this.input = input;
29     }
30
31     public NormalizedNode<?, ?> getInput() {
32         return input;
33     }
34
35     private void readObject(final ObjectInputStream stream) throws IOException, ClassNotFoundException, URISyntaxException {
36         NormalizedNodeStreamReader reader = new NormalizedNodeInputStreamReader(stream);
37         this.input = reader.readNormalizedNode();
38     }
39
40     private void writeObject(final ObjectOutputStream stream) throws IOException {
41         NormalizedNodeStreamWriter writer = new NormalizedNodeOutputStreamWriter(stream);
42         NormalizedNodeWriter normalizedNodeWriter = NormalizedNodeWriter.forStreamWriter(writer);
43
44         normalizedNodeWriter.write(this.input);
45     }
46
47 }