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.
29 public interface NormalizedNodeDataInput extends DataInput {
31 * Interpret current stream position as a NormalizedNode, stream its events into a NormalizedNodeStreamWriter.
33 * @param writer Writer to emit events to
34 * @throws IOException if an error occurs
35 * @throws IllegalStateException if the dictionary has been detached
36 * @throws NullPointerException if {@code writer} is null
38 void streamNormalizedNode(NormalizedNodeStreamWriter writer) throws IOException;
41 * Read a normalized node from the reader.
43 * @return Next node from the stream, or null if end of stream has been reached.
44 * @throws IOException if an error occurs
45 * @throws IllegalStateException if the dictionary has been detached
47 default NormalizedNode<?, ?> readNormalizedNode() throws IOException {
48 return readNormalizedNode(ReusableImmutableNormalizedNodeStreamWriter.create());
52 * Read a normalized node from the reader, using specified writer to construct the result.
54 * @param receiver Reusable receiver to, expected to be reset
55 * @return Next node from the stream, or null if end of stream has been reached.
56 * @throws IOException if an error occurs
57 * @throws IllegalStateException if the dictionary has been detached
59 default NormalizedNode<?, ?> readNormalizedNode(final ReusableStreamReceiver receiver) throws IOException {
61 streamNormalizedNode(receiver);
62 return receiver.getResult();
68 YangInstanceIdentifier readYangInstanceIdentifier() throws IOException;
70 @NonNull QName readQName() throws IOException;
72 PathArgument readPathArgument() throws IOException;
74 SchemaPath readSchemaPath() throws IOException;
77 * Return the version of the underlying input stream.
79 * @return Stream version
80 * @throws IOException if the version cannot be ascertained
82 NormalizedNodeStreamVersion getVersion() throws IOException;
84 default Optional<NormalizedNode<?, ?>> readOptionalNormalizedNode() throws IOException {
85 return readBoolean() ? Optional.of(readNormalizedNode()) : Optional.empty();