public class XMLSerializer extends AbstractXMLStreaming
KVStore
to/from XML.
The XML has a simple format; empty values may be omitted:
<xml version="1.0" encoding="UTF-8"?> <entries> <entry> <key>013f7b</key> <value>5502</value> </entry> <entry> <key>ee7698</key> </entry> ... </entries>
Modifier and Type | Field and Description |
---|---|
static QName |
ENTRIES_TAG |
static QName |
ENTRY_TAG |
static QName |
KEY_TAG |
static QName |
VALUE_TAG |
Constructor and Description |
---|
XMLSerializer(KVStore kv)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
int |
read(InputStream input)
Import key/value pairs into the
KVStore associated with this instance from the given XML input. |
int |
read(XMLStreamReader reader)
Import key/value pairs into the
KVStore associated with this instance from the given XML input. |
int |
write(OutputStream output,
boolean indent)
Export all key/value pairs from the
KVStore associated with this instance to the given output. |
int |
write(Writer writer,
boolean indent)
Export all key/value pairs from the
KVStore associated with this instance to the given writer. |
int |
write(XMLStreamWriter writer,
byte[] minKey,
byte[] maxKey)
Export a range of key/value pairs from the
KVStore associated with this instance to the given XML output. |
expect, expectClose, getAttr, getAttr, getBooleanAttr, getBooleanAttr, getIntAttr, getIntAttr, getLongAttr, newInvalidAttributeException, next, skip, writeElement
public static final QName ENTRIES_TAG
public static final QName ENTRY_TAG
public static final QName KEY_TAG
public static final QName VALUE_TAG
public XMLSerializer(KVStore kv)
kv
- key/value store on which to operateIllegalArgumentException
- if kv
is nullpublic int read(InputStream input) throws XMLStreamException
KVStore
associated with this instance from the given XML input.
The input
is not closed by this method.
input
- XML inputXMLStreamException
- if an error occursIllegalArgumentException
- if input
is nullpublic int read(XMLStreamReader reader) throws XMLStreamException
KVStore
associated with this instance from the given XML input.
This method expects to see an opening <entries>
as the next event (not counting whitespace, comments, etc.),
which is then consumed up through the closing </entries>
event. The reader
is not closed by this method.
Therefore, this tag could be part of a larger XML document.reader
- XML readerXMLStreamException
- if an error occursIllegalArgumentException
- if reader
is nullpublic int write(OutputStream output, boolean indent) throws XMLStreamException
KVStore
associated with this instance to the given output.
The output
is not closed by this method.
output
- XML output; will not be closed by this methodindent
- true to indent output, false for all on one lineXMLStreamException
- if an error occursIllegalArgumentException
- if output
is nullpublic int write(Writer writer, boolean indent) throws XMLStreamException
KVStore
associated with this instance to the given writer.
The writer
is not closed by this method.
writer
- XML output; will not be closed by this methodindent
- true to indent output, false for all on one lineXMLStreamException
- if an error occursIllegalArgumentException
- if writer
is nullpublic int write(XMLStreamWriter writer, byte[] minKey, byte[] maxKey) throws XMLStreamException
KVStore
associated with this instance to the given XML output.
This method writes a start element as its first action, allowing the output to be embedded into a larger XML document.
Callers not embedding the output may with to precede invocation of this method with a call to
writer.writeStartDocument()
.
The writer
is not closed by this method.
writer
- XML writer; will not be closed by this methodminKey
- minimum key (inclusive), or null for nonemaxKey
- maximum key (exclusive), or null for noneXMLStreamException
- if an error occursIllegalArgumentException
- if writer
is nullCopyright © 2022. All rights reserved.