Class NormalizedMetadataWriter

  • All Implemented Interfaces:
    Closeable, Flushable, AutoCloseable

    @Beta
    public final class NormalizedMetadataWriter
    extends Object
    implements Closeable, Flushable
    A utility class to attach 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.

    Author:
    Robert Varga
    • Method Detail

      • forStreamWriter

        public static @NonNull NormalizedMetadataWriter forStreamWriter​(org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter writer,
                                                                        boolean orderKeyLeaves)
        Create a new writer backed by a 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.
        Parameters:
        writer - Back-end writer
        orderKeyLeaves - whether the returned instance should be RFC6020 XML compliant.
        Returns:
        A new instance.
      • forStreamWriter

        public static @NonNull NormalizedMetadataWriter forStreamWriter​(org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter writer)
        Create a new writer backed by a NormalizedNodeStreamWriter. This is a convenience method for forStreamWriter(writer, true).
        Parameters:
        writer - Back-end writer
        Returns:
        A new instance.
      • write

        public @NonNull NormalizedMetadataWriter write​(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode<?,​?> data,
                                                       org.opendaylight.yangtools.rfc7952.data.api.NormalizedMetadata metadata)
                                                throws IOException
        Iterate over the provided NormalizedNode and NormalizedMetadata and emit write events to the encapsulated NormalizedNodeStreamWriter.
        Parameters:
        data - NormalizedNode data
        metadata - NormalizedMetadata metadata
        Returns:
        NormalizedNodeWriter this
        Throws:
        NullPointerException - if any argument is null
        IllegalArgumentException - if metadata does not match data
        IOException - when thrown from the backing writer.