--- /dev/null
+/*
+ * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.cluster.datastore.node.utils.stream;
+
+import com.google.common.annotations.Beta;
+import java.io.DataInput;
+import java.io.IOException;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;;
+
+/**
+ * Interface for reading {@link NormalizedNode}s, {@link YangInstanceIdentifier}s and {@link PathArgument}s.
+ */
+@Beta
+public interface NormalizedNodeDataInput extends DataInput {
+ /**
+ * Read a normalized node from the reader.
+ *
+ * @return Next node from the stream, or null if end of stream has been reached.
+ * @throws IOException if an error occurs
+ * @throws IllegalStateException if the dictionary has been detached
+ */
+ NormalizedNode<?, ?> readNormalizedNode() throws IOException;
+
+ YangInstanceIdentifier readYangInstanceIdentifier() throws IOException;
+
+ PathArgument readPathArgument() throws IOException;
+}
--- /dev/null
+/*
+ * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.cluster.datastore.node.utils.stream;
+
+import com.google.common.annotations.Beta;
+import java.io.DataOutput;
+import java.io.IOException;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;;
+
+/**
+ * Interface for emitting {@link NormalizedNode}s, {@link YangInstanceIdentifier}s and {@link PathArgument}s.
+ */
+@Beta
+public interface NormalizedNodeDataOutput extends DataOutput {
+ void writeNormalizedNode(NormalizedNode<?, ?> normalizedNode) throws IOException;
+ void writePathArgument(PathArgument pathArgument) throws IOException;
+ void writeYangInstanceIdentifier(YangInstanceIdentifier identifier) throws IOException;
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.cluster.datastore.node.utils.stream;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import javax.annotation.Nonnull;
+
+public final class NormalizedNodeInputOutput {
+ private NormalizedNodeInputOutput() {
+ throw new UnsupportedOperationException();
+ }
+
+ public static NormalizedNodeDataInput newDataInput(@Nonnull final DataInput input) throws IOException {
+ return new NormalizedNodeInputStreamReader(input);
+ }
+
+ public static NormalizedNodeDataOutput newDataOutput(@Nonnull final DataOutput output) throws IOException {
+ return new NormalizedNodeOutputStreamWriter(output);
+ }
+}
*
*/
-public class NormalizedNodeInputStreamReader implements NormalizedNodeStreamReader {
+public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput, NormalizedNodeStreamReader {
private static final Logger LOG = LoggerFactory.getLogger(NormalizedNodeInputStreamReader.class);
input = new DataInputStream(stream);
}
+ /**
+ * @deprecated Use {@link NormalizedNodeInputOutput#newDataInput(DataInput)} instead.
+ */
+ @Deprecated
public NormalizedNodeInputStreamReader(final DataInput input) {
this.input = Preconditions.checkNotNull(input);
}
return new String(bytes, StandardCharsets.UTF_8);
}
+ @Override
public YangInstanceIdentifier readYangInstanceIdentifier() throws IOException {
readSignatureMarkerAndVersionIfNeeded();
return readYangInstanceIdentifierInternal();
return children;
}
+ @Override
public PathArgument readPathArgument() throws IOException {
// read Type
int type = input.readByte();
}
return builder;
}
+
+ @Override
+ public void readFully(byte[] b) throws IOException {
+ readSignatureMarkerAndVersionIfNeeded();
+ input.readFully(b);
+ }
+
+ @Override
+ public void readFully(byte[] b, int off, int len) throws IOException {
+ readSignatureMarkerAndVersionIfNeeded();
+ input.readFully(b, off, len);
+ }
+
+ @Override
+ public int skipBytes(int n) throws IOException {
+ readSignatureMarkerAndVersionIfNeeded();
+ return input.skipBytes(n);
+ }
+
+ @Override
+ public boolean readBoolean() throws IOException {
+ readSignatureMarkerAndVersionIfNeeded();
+ return input.readBoolean();
+ }
+
+ @Override
+ public byte readByte() throws IOException {
+ readSignatureMarkerAndVersionIfNeeded();
+ return input.readByte();
+ }
+
+ @Override
+ public int readUnsignedByte() throws IOException {
+ readSignatureMarkerAndVersionIfNeeded();
+ return input.readUnsignedByte();
+ }
+
+ @Override
+ public short readShort() throws IOException {
+ readSignatureMarkerAndVersionIfNeeded();
+ return input.readShort();
+ }
+
+ @Override
+ public int readUnsignedShort() throws IOException {
+ readSignatureMarkerAndVersionIfNeeded();
+ return input.readUnsignedShort();
+ }
+
+ @Override
+ public char readChar() throws IOException {
+ readSignatureMarkerAndVersionIfNeeded();
+ return input.readChar();
+ }
+
+ @Override
+ public int readInt() throws IOException {
+ readSignatureMarkerAndVersionIfNeeded();
+ return input.readInt();
+ }
+
+ @Override
+ public long readLong() throws IOException {
+ readSignatureMarkerAndVersionIfNeeded();
+ return input.readLong();
+ }
+
+ @Override
+ public float readFloat() throws IOException {
+ readSignatureMarkerAndVersionIfNeeded();
+ return input.readFloat();
+ }
+
+ @Override
+ public double readDouble() throws IOException {
+ readSignatureMarkerAndVersionIfNeeded();
+ return input.readDouble();
+ }
+
+ @Override
+ public String readLine() throws IOException {
+ readSignatureMarkerAndVersionIfNeeded();
+ return input.readLine();
+ }
+
+ @Override
+ public String readUTF() throws IOException {
+ readSignatureMarkerAndVersionIfNeeded();
+ return input.readUTF();
+ }
}
*
*/
-public class NormalizedNodeOutputStreamWriter implements NormalizedNodeStreamWriter {
+public class NormalizedNodeOutputStreamWriter implements NormalizedNodeDataOutput, NormalizedNodeStreamWriter {
private static final Logger LOG = LoggerFactory.getLogger(NormalizedNodeOutputStreamWriter.class);
this((DataOutput) new DataOutputStream(Preconditions.checkNotNull(stream)));
}
- public NormalizedNodeOutputStreamWriter(DataOutput output) {
+ /**
+ * @deprecated Use {@link NormalizedNodeInputOutput#newDataOutput(DataOutput)} instead.
+ */
+ @Deprecated
+ public NormalizedNodeOutputStreamWriter(final DataOutput output) {
this.output = Preconditions.checkNotNull(output);
}
return normalizedNodeWriter;
}
+ @Override
public void writeNormalizedNode(NormalizedNode<?, ?> node) throws IOException {
writeSignatureMarkerAndVersionIfNeeded();
normalizedNodeWriter().write(node);
}
}
+ @Override
public void writeYangInstanceIdentifier(YangInstanceIdentifier identifier) throws IOException {
writeSignatureMarkerAndVersionIfNeeded();
writeYangInstanceIdentifierInternal(identifier);
}
}
+ @Override
public void writePathArgument(YangInstanceIdentifier.PathArgument pathArgument) throws IOException {
byte type = PathArgumentTypes.getSerializablePathArgumentType(pathArgument);
output.writeByte(type);
switch(type) {
- case PathArgumentTypes.NODE_IDENTIFIER :
+ case PathArgumentTypes.NODE_IDENTIFIER:
YangInstanceIdentifier.NodeIdentifier nodeIdentifier =
(YangInstanceIdentifier.NodeIdentifier) pathArgument;
break;
}
}
+
+ @Override
+ public void write(int b) throws IOException {
+ writeSignatureMarkerAndVersionIfNeeded();
+ output.write(b);
+ }
+
+ @Override
+ public void write(byte[] b) throws IOException {
+ writeSignatureMarkerAndVersionIfNeeded();
+ output.write(b);
+ }
+
+ @Override
+ public void write(byte[] b, int off, int len) throws IOException {
+ writeSignatureMarkerAndVersionIfNeeded();
+ output.write(b, off, len);
+ }
+
+ @Override
+ public void writeBoolean(boolean v) throws IOException {
+ writeSignatureMarkerAndVersionIfNeeded();
+ output.writeBoolean(v);
+ }
+
+ @Override
+ public void writeByte(int v) throws IOException {
+ writeSignatureMarkerAndVersionIfNeeded();
+ output.writeByte(v);
+ }
+
+ @Override
+ public void writeShort(int v) throws IOException {
+ writeSignatureMarkerAndVersionIfNeeded();
+ output.writeShort(v);
+ }
+
+ @Override
+ public void writeChar(int v) throws IOException {
+ writeSignatureMarkerAndVersionIfNeeded();
+ output.writeChar(v);
+ }
+
+ @Override
+ public void writeInt(int v) throws IOException {
+ writeSignatureMarkerAndVersionIfNeeded();
+ output.writeInt(v);
+ }
+
+ @Override
+ public void writeLong(long v) throws IOException {
+ writeSignatureMarkerAndVersionIfNeeded();
+ output.writeLong(v);
+ }
+
+ @Override
+ public void writeFloat(float v) throws IOException {
+ writeSignatureMarkerAndVersionIfNeeded();
+ output.writeFloat(v);
+ }
+
+ @Override
+ public void writeDouble(double v) throws IOException {
+ writeSignatureMarkerAndVersionIfNeeded();
+ output.writeDouble(v);
+ }
+
+ @Override
+ public void writeBytes(String s) throws IOException {
+ writeSignatureMarkerAndVersionIfNeeded();
+ output.writeBytes(s);
+ }
+
+ @Override
+ public void writeChars(String s) throws IOException {
+ writeSignatureMarkerAndVersionIfNeeded();
+ output.writeChars(s);
+ }
+
+ @Override
+ public void writeUTF(String s) throws IOException {
+ writeSignatureMarkerAndVersionIfNeeded();
+ output.writeUTF(s);
+ }
}
package org.opendaylight.controller.cluster.datastore.node.utils.stream;
-import java.io.IOException;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-
/**
* Interface for a class that can read serialized NormalizedNode instances from a stream.
+ *
+ * @deprecated Use {@link NormalizedNodeDataInput} instead.
*/
-public interface NormalizedNodeStreamReader {
-
- NormalizedNode<?, ?> readNormalizedNode() throws IOException;
+public interface NormalizedNodeStreamReader extends NormalizedNodeDataInput {
}