Class NormalizedMetadataWriter
- java.lang.Object
-
- org.opendaylight.yangtools.rfc7952.data.util.NormalizedMetadataWriter
-
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
@Beta public final class NormalizedMetadataWriter extends Object implements Closeable, Flushable
A utility class to attachNormalizedMetadata
into a NormalizedNode stream, such as the one produced byNormalizedNodeWriter
, so that a targetNormalizedNodeStreamWriter
sees both data and metadata in the stream. A typical use would like this:// Data for output NormalizedNode<?, ?> data; // Metadata for output NormalizedMetadata metadata; // Target output writer NormalizedNodeStreamWriter output = ...; // Metadata writer NormalizedMetadataStreamWriter metaWriter = NormalizedMetadataWriter.forStreamWriter(output); // Write a normalized node and its metadata dataWriter.write(data, metadata);
This class is NOT thread-safe.
- Author:
- Robert Varga
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
void
flush()
static @NonNull NormalizedMetadataWriter
forStreamWriter(NormalizedNodeStreamWriter writer)
Create a new writer backed by aNormalizedNodeStreamWriter
.static @NonNull NormalizedMetadataWriter
forStreamWriter(NormalizedNodeStreamWriter writer, boolean orderKeyLeaves)
Create a new writer backed by aNormalizedNodeStreamWriter
.@NonNull NormalizedMetadataWriter
write(NormalizedNode<?,?> data, NormalizedMetadata metadata)
Iterate over the providedNormalizedNode
andNormalizedMetadata
and emit write events to the encapsulatedNormalizedNodeStreamWriter
.
-
-
-
Method Detail
-
forStreamWriter
public static @NonNull NormalizedMetadataWriter forStreamWriter(NormalizedNodeStreamWriter writer, boolean orderKeyLeaves)
Create a new writer backed by aNormalizedNodeStreamWriter
. Unlike the simpleforStreamWriter(NormalizedNodeStreamWriter)
method, this allows the caller to switch off RFC6020 XML compliance, providing better throughput. The reason is that the XML mapping rules in RFC6020 require the encoding to emit leaf nodes which participate in a list's key first and in the order in which they are defined in the key. For JSON, this requirement is completely relaxed and leaves can be ordered in any way we see fit. The former requires a bit of work: first a lookup for each key and then for each emitted node we need to check whether it was already emitted.- Parameters:
writer
- Back-end writerorderKeyLeaves
- whether the returned instance should be RFC6020 XML compliant.- Returns:
- A new instance.
-
forStreamWriter
public static @NonNull NormalizedMetadataWriter forStreamWriter(NormalizedNodeStreamWriter writer)
Create a new writer backed by aNormalizedNodeStreamWriter
. This is a convenience method forforStreamWriter(writer, true)
.- Parameters:
writer
- Back-end writer- Returns:
- A new instance.
-
write
public @NonNull NormalizedMetadataWriter write(NormalizedNode<?,?> data, NormalizedMetadata metadata) throws IOException
Iterate over the providedNormalizedNode
andNormalizedMetadata
and emit write events to the encapsulatedNormalizedNodeStreamWriter
.- Parameters:
data
- NormalizedNode datametadata
-NormalizedMetadata
metadata- Returns:
- NormalizedNodeWriter this
- Throws:
NullPointerException
- if any argument is nullIllegalArgumentException
- if metadata does not match dataIOException
- when thrown from the backing writer.
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
flush
public void flush() throws IOException
- Specified by:
flush
in interfaceFlushable
- Throws:
IOException
-
-