@Beta public class NormalizedNodeWriter extends Object implements Closeable, Flushable
NormalizedNode
. This is essentially
the opposite of a XMLStreamReader
-- unlike instantiating an iterator over
the backing data, this encapsulates a NormalizedNodeStreamWriter
and allows
us to write multiple nodes.Modifier and Type | Method and Description |
---|---|
void |
close() |
void |
flush() |
static NormalizedNodeWriter |
forStreamWriter(NormalizedNodeStreamWriter writer)
Create a new writer backed by a
NormalizedNodeStreamWriter . |
static NormalizedNodeWriter |
forStreamWriter(NormalizedNodeStreamWriter writer,
boolean orderKeyLeaves)
Create a new writer backed by a
NormalizedNodeStreamWriter . |
protected NormalizedNodeStreamWriter |
getWriter() |
NormalizedNodeWriter |
write(NormalizedNode<?,?> node)
Iterate over the provided
NormalizedNode and emit write
events to the encapsulated NormalizedNodeStreamWriter . |
protected boolean |
writeChildren(Iterable<? extends NormalizedNode<?,?>> children)
Emit events for all children and then emit an endNode() event.
|
protected boolean |
writeMapEntryNode(MapEntryNode node) |
protected final NormalizedNodeStreamWriter getWriter()
public static NormalizedNodeWriter forStreamWriter(NormalizedNodeStreamWriter writer)
NormalizedNodeStreamWriter
.writer
- Back-end writerpublic static NormalizedNodeWriter 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 final NormalizedNodeWriter write(NormalizedNode<?,?> node) throws IOException
NormalizedNode
and emit write
events to the encapsulated NormalizedNodeStreamWriter
.node
- NodeIOException
- when thrown from the backing writer.public void flush() throws IOException
flush
in interface Flushable
IOException
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
protected final boolean writeChildren(Iterable<? extends NormalizedNode<?,?>> children) throws IOException
children
- Child iterableIOException
- when the writer reports itprotected boolean writeMapEntryNode(MapEntryNode node) throws IOException
IOException
Copyright © 2017 OpenDaylight. All rights reserved.