2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.cluster.datastore.node.utils.stream;
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;
17 public final class NormalizedNodeInputOutput {
18 private NormalizedNodeInputOutput() {
19 throw new UnsupportedOperationException();
23 * Creates a new {@link NormalizedNodeDataInput} instance that reads from the given input. This method first reads
24 * and validates that the input contains a valid NormalizedNode stream.
26 * @param input the DataInput to read from
27 * @return a new {@link NormalizedNodeDataInput} instance
28 * @throws IOException if an error occurs reading from the input
30 public static NormalizedNodeDataInput newDataInput(final @NonNull DataInput input) throws IOException {
31 final byte marker = input.readByte();
32 if (marker != TokenTypes.SIGNATURE_MARKER) {
33 throw new InvalidNormalizedNodeStreamException(String.format("Invalid signature marker: %d", marker));
36 final short version = input.readShort();
38 case TokenTypes.LITHIUM_VERSION:
39 return new NormalizedNodeInputStreamReader(input, true);
41 throw new InvalidNormalizedNodeStreamException(String.format("Unhandled stream version %s", version));
46 * Creates a new {@link NormalizedNodeDataInput} instance that reads from the given input. This method does not
47 * perform any initial validation of the input stream.
49 * @param input the DataInput to read from
50 * @return a new {@link NormalizedNodeDataInput} instance
52 public static NormalizedNodeDataInput newDataInputWithoutValidation(final @NonNull DataInput input) {
53 return new NormalizedNodeInputStreamReader(input, false);
57 * Creates a new {@link NormalizedNodeDataOutput} instance that writes to the given output.
59 * @param output the DataOutput to write to
60 * @return a new {@link NormalizedNodeDataOutput} instance
62 public static NormalizedNodeDataOutput newDataOutput(final @NonNull DataOutput output) {
63 return new NormalizedNodeOutputStreamWriter(output);