Package io.permazen.kv.util
Class XMLSerializer
java.lang.Object
io.permazen.util.AbstractXMLStreaming
io.permazen.kv.util.XMLSerializer
Utility methods for serializing and deserializing the contents of a
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>
-
Field Summary
Modifier and TypeFieldDescriptionstatic final QName
static final QName
static final QName
static final QName
Fields inherited from class io.permazen.util.AbstractXMLStreaming
log
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
read
(InputStream input) Import key/value pairs into theKVStore
associated with this instance from the given XML input.int
read
(XMLStreamReader reader) Import key/value pairs into theKVStore
associated with this instance from the given XML input.int
write
(OutputStream output, boolean indent) Export all key/value pairs from theKVStore
associated with this instance to the given output.int
Export all key/value pairs from theKVStore
associated with this instance to the given writer.int
write
(XMLStreamWriter writer, byte[] minKey, byte[] maxKey) Export a range of key/value pairs from theKVStore
associated with this instance to the given XML output.Methods inherited from class io.permazen.util.AbstractXMLStreaming
expect, expectClose, getAttr, getAttr, getBooleanAttr, getBooleanAttr, getIntAttr, getIntAttr, getLongAttr, newInvalidAttributeException, newInvalidInputException, newInvalidInputException, next, skip, writeAttr, writeCData, writeCharacters, writeElement, writeEmptyElement, writeStartElement
-
Field Details
-
ENTRIES_TAG
-
ENTRY_TAG
-
KEY_TAG
-
VALUE_TAG
-
-
Constructor Details
-
XMLSerializer
Constructor.- Parameters:
kv
- key/value store on which to operate- Throws:
IllegalArgumentException
- ifkv
is null
-
-
Method Details
-
read
Import key/value pairs into theKVStore
associated with this instance from the given XML input.The
input
is not closed by this method.- Parameters:
input
- XML input- Returns:
- the number of key/value pairs read
- Throws:
XMLStreamException
- if an error occursIllegalArgumentException
- ifinput
is null
-
read
Import key/value pairs into theKVStore
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. Thereader
is not closed by this method. Therefore, this tag could be part of a larger XML document.- Parameters:
reader
- XML reader- Returns:
- the number of key/value pairs read
- Throws:
XMLStreamException
- if an error occursIllegalArgumentException
- ifreader
is null
-
write
Export all key/value pairs from theKVStore
associated with this instance to the given output.The
output
is not closed by this method.- Parameters:
output
- XML output; will not be closed by this methodindent
- true to indent output, false for all on one line- Returns:
- the number of key/value pairs written
- Throws:
XMLStreamException
- if an error occursIllegalArgumentException
- ifoutput
is null
-
write
Export all key/value pairs from theKVStore
associated with this instance to the given writer.The
writer
is not closed by this method.- Parameters:
writer
- XML output; will not be closed by this methodindent
- true to indent output, false for all on one line- Returns:
- the number of key/value pairs written
- Throws:
XMLStreamException
- if an error occursIllegalArgumentException
- ifwriter
is null
-
write
Export a range of key/value pairs from theKVStore
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.- Parameters:
writer
- XML writer; will not be closed by this methodminKey
- minimum key (inclusive), or null for nonemaxKey
- maximum key (exclusive), or null for none- Returns:
- the number of key/value pairs written
- Throws:
XMLStreamException
- if an error occursIllegalArgumentException
- ifwriter
is null
-