@Beta public final class NormalizedMetadataWriter extends Object implements Closeable, Flushable
NormalizedMetadata
into a NormalizedNode stream, such as the one produced by
NormalizedNodeWriter
, so that a target NormalizedNodeStreamWriter
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.
Modifier and Type | Method and Description |
---|---|
void |
close() |
void |
flush() |
static @NonNull NormalizedMetadataWriter |
forStreamWriter(NormalizedNodeStreamWriter writer)
Create a new writer backed by a
NormalizedNodeStreamWriter . |
static @NonNull NormalizedMetadataWriter |
forStreamWriter(NormalizedNodeStreamWriter writer,
boolean orderKeyLeaves)
Create a new writer backed by a
NormalizedNodeStreamWriter . |
@NonNull NormalizedMetadataWriter |
write(NormalizedNode<?,?> data,
NormalizedMetadata metadata)
Iterate over the provided
NormalizedNode and NormalizedMetadata and emit write events to the
encapsulated NormalizedNodeStreamWriter . |
public static @NonNull NormalizedMetadataWriter forStreamWriter(NormalizedNodeStreamWriter writer, boolean orderKeyLeaves)
NormalizedNodeStreamWriter
. Unlike the simple
forStreamWriter(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.writer
- Back-end writerorderKeyLeaves
- whether the returned instance should be RFC6020 XML compliant.public static @NonNull NormalizedMetadataWriter forStreamWriter(NormalizedNodeStreamWriter writer)
NormalizedNodeStreamWriter
. This is a convenience method for
forStreamWriter(writer, true)
.writer
- Back-end writerpublic @NonNull NormalizedMetadataWriter write(NormalizedNode<?,?> data, NormalizedMetadata metadata) throws IOException
NormalizedNode
and NormalizedMetadata
and emit write events to the
encapsulated NormalizedNodeStreamWriter
.data
- NormalizedNode datametadata
- NormalizedMetadata
metadataNullPointerException
- if any argument is nullIllegalArgumentException
- if metadata does not match dataIOException
- when thrown from the backing writer.public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
public void flush() throws IOException
flush
in interface Flushable
IOException
Copyright © 2019 OpenDaylight. All rights reserved.