Package io.jenetics.xml.stream
Class XML
- java.lang.Object
-
- io.jenetics.xml.stream.XML
-
public final class XML extends Object
This class contains helper methods for creatingXMLStreamReader
andXMLStreamWriter
objects.Creating a new XML stream reader:
Create a new XML stream reader:try (AutoCloseableXMLStreamReader xml = XML.reader(in)) { // Move XML stream to first element. xml.next(); return reader.read(xml); }
Create a new XML stream reader with pretty-print-indentation: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
All Methods Static Methods Concrete Methods Modifier and Type Method Description static 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 Detail
-
reader
public static AutoCloseableXMLStreamReader reader(InputStream input) throws XMLStreamException
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
public static AutoCloseableXMLStreamWriter writer(OutputStream output) 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 stream- Returns:
- a new
XMLStreamWriter
instance - Throws:
XMLStreamException
- if an error occurs while creating the XML stream writerNullPointerException
- if the givenoutput
stream isnull
-
-