java.lang.Object
io.jenetics.xml.stream.XML
This class contains helper methods for creating
Create a new XML stream reader:
Create a new XML stream reader with pretty-print-indentation:
XMLStreamReader
and
XMLStreamWriter
objects.
Creating a new XML stream reader:
try (AutoCloseableXMLStreamReader xml = XML.reader(in)) {
// Move XML stream to first element.
xml.next();
return reader.read(xml);
}
try (AutoCloseableXMLStreamWriter xml = XML.writer(out)) {
writer.write(value, xml);
}
final String indent = " ";
try (AutoCloseableXMLStreamWriter xml = XML.writer(out, indent)) {
writer.write(value, xml);
}
- Since:
- 3.9
- Version:
- 3.9
-
Method Summary
Modifier and TypeMethodDescriptionstatic AutoCloseableXMLStreamReader
reader
(InputStream input) Create a new XML stream reader from the giveninput
stream.static AutoCloseableXMLStreamWriter
writer
(OutputStream output) Create a newXMLStreamWriter
from the given output stream.static AutoCloseableXMLStreamWriter
writer
(OutputStream output, String indent) Create a newXMLStreamWriter
from the given output stream.
-
Method Details
-
reader
Create a new XML stream reader from the giveninput
stream. The caller is responsible for closing the returnedXMLStreamReader
.try (AutoCloseableXMLStreamReader xml = XML.reader(in)) { // Move XML stream to first element. xml.next(); return reader.read(xml); }
- Parameters:
input
- the input stream- Returns:
- a new
Closeable
XML stream reader - Throws:
XMLStreamException
- if the creation of the XML stream reader failsNullPointerException
- if the giveninput
stream isnull
-
writer
public static AutoCloseableXMLStreamWriter writer(OutputStream output, String indent) throws XMLStreamException Create a newXMLStreamWriter
from the given output stream. The caller is responsible for closing the returnedXMLStreamWriter
.try (AutoCloseableXMLStreamWriter xml = XML.writer(out, " ")) { writer.write(value, xml); }
- Parameters:
output
- the underlying output streamindent
- the element indent used for the XML output- Returns:
- a new
XMLStreamWriter
instance - Throws:
XMLStreamException
- if an error occurs while creating the XML stream writerNullPointerException
- if the givenoutput
stream isnull
-
writer
Create a newXMLStreamWriter
from the given output stream. The caller is responsible for closing the returnedXMLStreamWriter
.try (AutoCloseableXMLStreamWriter xml = XML.writer(out)) { writer.write(value, xml); }
- Parameters:
output
- the underlying output stream- Returns:
- a new
XMLStreamWriter
instance - Throws:
XMLStreamException
- if an error occurs while creating the XML stream writerNullPointerException
- if the givenoutput
stream isnull
-