055721d1120dda25275a09715b52bd07d456c3a1
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / main / java / org / opendaylight / controller / cluster / datastore / node / utils / stream / NormalizedNodeInputOutput.java
1 /*
2  * Copyright (c) 2015 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 package org.opendaylight.controller.cluster.datastore.node.utils.stream;
9
10 import com.google.common.annotations.Beta;
11 import java.io.DataInput;
12 import java.io.DataOutput;
13 import java.io.IOException;
14 import org.eclipse.jdt.annotation.NonNull;
15
16 @Beta
17 @Deprecated(forRemoval = true)
18 public final class NormalizedNodeInputOutput {
19     private NormalizedNodeInputOutput() {
20         throw new UnsupportedOperationException();
21     }
22
23     /**
24      * Creates a new {@link NormalizedNodeDataInput} instance that reads from the given input. This method first reads
25      * and validates that the input contains a valid NormalizedNode stream.
26      *
27      * @param input the DataInput to read from
28      * @return a new {@link NormalizedNodeDataInput} instance
29      * @throws IOException if an error occurs reading from the input
30      */
31     public static NormalizedNodeDataInput newDataInput(final @NonNull DataInput input) throws IOException {
32         try {
33             return new CompatNormalizedNodeDataInput(org.opendaylight.yangtools.yang.data.codec.binfmt
34                 .NormalizedNodeDataInput.newDataInput(input));
35         } catch (org.opendaylight.yangtools.yang.data.codec.binfmt.InvalidNormalizedNodeStreamException e) {
36             throw new InvalidNormalizedNodeStreamException(e.getMessage(), e);
37         }
38     }
39
40     /**
41      * Creates a new {@link NormalizedNodeDataInput} instance that reads from the given input. This method does not
42      * perform any initial validation of the input stream.
43      *
44      * @param input the DataInput to read from
45      * @return a new {@link NormalizedNodeDataInput} instance
46      */
47     public static NormalizedNodeDataInput newDataInputWithoutValidation(final @NonNull DataInput input) {
48         return new CompatNormalizedNodeDataInput(org.opendaylight.yangtools.yang.data.codec.binfmt
49             .NormalizedNodeDataInput.newDataInputWithoutValidation(input));
50     }
51
52     /**
53      * Creates a new {@link NormalizedNodeDataOutput} instance that writes to the given output and latest current
54      * stream version.
55      *
56      * @param output the DataOutput to write to
57      * @return a new {@link NormalizedNodeDataOutput} instance
58      */
59     public static NormalizedNodeDataOutput newDataOutput(final @NonNull DataOutput output) {
60         return newDataOutput(output, NormalizedNodeStreamVersion.MAGNESIUM);
61     }
62
63     /**
64      * Creates a new {@link NormalizedNodeDataOutput} instance that writes to the given output.
65      *
66      * @param output the DataOutput to write to
67      * @param version Streaming version to use
68      * @return a new {@link NormalizedNodeDataOutput} instance
69      */
70     public static NormalizedNodeDataOutput newDataOutput(final @NonNull DataOutput output,
71             final @NonNull NormalizedNodeStreamVersion version) {
72         return new CompatNormalizedNodeDataOutput(version.toYangtools().newDataOutput(output));
73     }
74 }