Package org.dellroad.stuff.xml
Class IndentXMLEventWriter
java.lang.Object
org.dellroad.stuff.xml.EventWriterDelegate
org.dellroad.stuff.xml.IndentXMLEventWriter
- All Implemented Interfaces:
XMLEventConsumer
,XMLEventWriter
Wrapper for an underlying
XMLEventWriter
that automatically adds indentation to the event stream.-
Field Summary
Modifier and TypeFieldDescriptionprotected final XMLEventFactory
The configured event factory for this instance. -
Constructor Summary
ConstructorDescriptionIndentXMLEventWriter
(XMLEventWriter writer, int indent) Convenience constructor.IndentXMLEventWriter
(XMLEventWriter writer, XMLEventFactory factory, int indent) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
add
(XMLEventReader reader) protected void
indent
(int depth) Emit a newline followed by indentation to the given depth.Methods inherited from class org.dellroad.stuff.xml.EventWriterDelegate
close, flush, getNamespaceContext, getParent, getPrefix, setDefaultNamespace, setNamespaceContext, setParent, setPrefix
-
Field Details
-
factory
The configured event factory for this instance.
-
-
Constructor Details
-
IndentXMLEventWriter
Constructor.- Parameters:
writer
- underlying writerfactory
- event factoryindent
- indent amount, or negative to not add any whitespace- Throws:
IllegalArgumentException
- ifwriter
orfactory
is null
-
IndentXMLEventWriter
Convenience constructor. Equivalent to:IndentXMLEventWriter(writer, XMLEventFactory.newFactory(), indent)
- Parameters:
writer
- underlying writerindent
- indent amount, or negative to not add any whitespace- Throws:
IllegalArgumentException
- ifwriter
orfactory
is null
-
-
Method Details
-
add
- Specified by:
add
in interfaceXMLEventConsumer
- Specified by:
add
in interfaceXMLEventWriter
- Overrides:
add
in classEventWriterDelegate
- Throws:
XMLStreamException
-
add
- Specified by:
add
in interfaceXMLEventWriter
- Overrides:
add
in classEventWriterDelegate
- Throws:
XMLStreamException
-
indent
Emit a newline followed by indentation to the given depth.- Parameters:
depth
- indentation depth- Throws:
XMLStreamException
- if an XML error occurs
-