2 * Copyright (c) 2014, 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.IOException;
13 import java.util.Optional;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
18 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
19 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
20 import org.opendaylight.yangtools.yang.data.api.schema.stream.ReusableStreamReceiver;
21 import org.opendaylight.yangtools.yang.data.impl.schema.ReusableImmutableNormalizedNodeStreamWriter;
22 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
25 * Interface for reading {@link NormalizedNode}s, {@link YangInstanceIdentifier}s, {@link PathArgument}s
26 * and {@link SchemaPath}s.
28 * @deprecated Use {@link org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeDataInput} instead.
30 @Deprecated(forRemoval = true)
32 public interface NormalizedNodeDataInput extends DataInput {
34 * Interpret current stream position as a NormalizedNode, stream its events into a NormalizedNodeStreamWriter.
36 * @param writer Writer to emit events to
37 * @throws IOException if an error occurs
38 * @throws IllegalStateException if the dictionary has been detached
39 * @throws NullPointerException if {@code writer} is null
41 void streamNormalizedNode(NormalizedNodeStreamWriter writer) throws IOException;
44 * Read a normalized node from the reader.
46 * @return Next node from the stream, or null if end of stream has been reached.
47 * @throws IOException if an error occurs
48 * @throws IllegalStateException if the dictionary has been detached
50 default NormalizedNode<?, ?> readNormalizedNode() throws IOException {
51 return readNormalizedNode(ReusableImmutableNormalizedNodeStreamWriter.create());
55 * Read a normalized node from the reader, using specified writer to construct the result.
57 * @param receiver Reusable receiver to, expected to be reset
58 * @return Next node from the stream, or null if end of stream has been reached.
59 * @throws IOException if an error occurs
60 * @throws IllegalStateException if the dictionary has been detached
62 default NormalizedNode<?, ?> readNormalizedNode(final ReusableStreamReceiver receiver) throws IOException {
64 streamNormalizedNode(receiver);
65 return receiver.getResult();
71 YangInstanceIdentifier readYangInstanceIdentifier() throws IOException;
73 @NonNull QName readQName() throws IOException;
75 PathArgument readPathArgument() throws IOException;
77 SchemaPath readSchemaPath() throws IOException;
80 * Return the version of the underlying input stream.
82 * @return Stream version
83 * @throws IOException if the version cannot be ascertained
85 NormalizedNodeStreamVersion getVersion() throws IOException;
87 default Optional<NormalizedNode<?, ?>> readOptionalNormalizedNode() throws IOException {
88 return readBoolean() ? Optional.of(readNormalizedNode()) : Optional.empty();