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 creatingXMLStreamReaderandXMLStreamWriterobjects.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 AutoCloseableXMLStreamReaderreader(InputStream input)Create a new XML stream reader from the giveninputstream.static AutoCloseableXMLStreamWriterwriter(OutputStream output)Create a newXMLStreamWriterfrom the given output stream.static AutoCloseableXMLStreamWriterwriter(OutputStream output, String indent)Create a newXMLStreamWriterfrom the given output stream.
-
-
-
Method Detail
-
reader
public static AutoCloseableXMLStreamReader reader(InputStream input) throws XMLStreamException
Create a new XML stream reader from the giveninputstream. 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
CloseableXML stream reader - Throws:
XMLStreamException- if the creation of the XML stream reader failsNullPointerException- if the giveninputstream isnull
-
writer
public static AutoCloseableXMLStreamWriter writer(OutputStream output, String indent) throws XMLStreamException
Create a newXMLStreamWriterfrom 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
XMLStreamWriterinstance - Throws:
XMLStreamException- if an error occurs while creating the XML stream writerNullPointerException- if the givenoutputstream isnull
-
writer
public static AutoCloseableXMLStreamWriter writer(OutputStream output) throws XMLStreamException
Create a newXMLStreamWriterfrom 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
XMLStreamWriterinstance - Throws:
XMLStreamException- if an error occurs while creating the XML stream writerNullPointerException- if the givenoutputstream isnull
-
-