java.lang.Object
net.luis.utils.io.data.xml.XmlWriter
- All Implemented Interfaces:
AutoCloseable
A xml writer for writing xml elements to an output.
The writer expects only one xml element per output.
The writer expects only one xml element per output.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final XmlConfig
The xml config used by the writer.private final BufferedWriter
The internal writer used to write the xml elements.private boolean
A flag indicating whether the xml declaration was already written. -
Constructor Summary
ConstructorsConstructorDescriptionXmlWriter
(@NotNull OutputProvider output) Constructs a new xml writer with the default configuration.XmlWriter
(@NotNull OutputProvider output, @NotNull XmlConfig config) Constructs a new xml writer with the given configuration. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
void
writeDeclaration
(@NotNull XmlDeclaration declaration) Writes the given xml declaration to the output.void
writeXml
(@NotNull XmlElement element) Writes the given xml element to the output.
-
Field Details
-
config
The xml config used by the writer. -
writer
The internal writer used to write the xml elements. -
wroteDeclaration
private boolean wroteDeclarationA flag indicating whether the xml declaration was already written.
-
-
Constructor Details
-
XmlWriter
Constructs a new xml writer with the default configuration.- Parameters:
output
- The output to create the writer for- Throws:
NullPointerException
- If the output is null
-
XmlWriter
Constructs a new xml writer with the given configuration.- Parameters:
output
- The output to create the writer forconfig
- The configuration to use for the writer- Throws:
NullPointerException
- If the output or the configuration is null
-
-
Method Details
-
writeDeclaration
Writes the given xml declaration to the output.- Parameters:
declaration
- The xml declaration to write- Throws:
NullPointerException
- If the xml declaration is nullIllegalStateException
- If the xml declaration was already written (strict mode)UncheckedIOException
- If an I/O error occurs
-
writeXml
Writes the given xml element to the output.- Parameters:
element
- The xml element to write- Throws:
NullPointerException
- If the xml element is nullIllegalStateException
- If the xml declaration was not written before the xml element (strict mode)UncheckedIOException
- If an I/O error occurs
-
close
- Specified by:
close
in interfaceAutoCloseable
- Throws:
IOException
-