java.lang.Object
org.rrd4j.core.XmlWriter
- All Implemented Interfaces:
AutoCloseable
Extremely simple utility class used to create XML documents.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceFunctional interface for formatting double values in XML output.Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final StringHow NaN is written when no other form is given.private final XmlWriter.DoubleFormaterDouble formatterprivate final StringBuilderIndentation of the element currently being written.(package private) static final StringIndentation string for XML outputprivate static final java.time.format.DateTimeFormatterTimestamp format written into the XML, in UTC.Elements not yet closed, innermost last.private static final StringAttribute name carrying the RRD tool style.private final java.time.format.DateTimeFormatterTime formatterprivate final PrintWriterWhere the XML is written.Constructor Summary
ModifierConstructorDescriptionXmlWriter(OutputStream stream) Creates XmlWriter with the specifiedOutputStreamto send XML code to.XmlWriter(OutputStream stream, boolean autoFlush) Creates XmlWriter with the specified output stream to send XML code to.XmlWriter(PrintWriter stream) Creates XmlWriter with the specifiedPrintWriterto send XML code to.privateXmlWriter(PrintWriter writer, java.time.format.DateTimeFormatter timeFormatter, XmlWriter.DoubleFormater doubleFormatter) Creates a writer for one XML document.Method Summary
Modifier and TypeMethodDescriptionvoidclose()Flushes the underlying writer, then closes it.voidcloseTag()Closes the corresponding XML tagprivate static StringEscapes XML special characters in a string.voidflush()Flushes the output streamformatTimestamp(long timestamp) Formats a timestamp using the configuredDateTimeFormatter.voidOpens XML tagwithDoubleFormatter(XmlWriter.DoubleFormater doubleFormatter) Return a newXmlWriterthat will format time stamp using thisZoneIdwithTimeZone(java.time.ZoneId zid) Return a newXmlWriterthat will format time stamp as ISO 8601 with this explicit time zoneZoneIdvoidwriteComment(long timestamp) Writes a timestamp using the configuredDateTimeFormatteras an XML comment to output stream.voidwriteComment(Object comment) Writes XML comment to output streamvoidWrites <tag>value</tag> to output streamvoidWrites <tag>value</tag> to output streamvoidWrites <tag>value</tag> to output streamvoidWrites <tag>value</tag> to output streamvoidWrites <tag>value</tag> to output streamvoidWrites <tag>value</tag> to output streamvoidWrites <tag>value</tag> to output streamvoidWrites <tag>value</tag> to output streamvoidWrites <tag>value</tag> to output stream
Field Details
INDENT_STR
STYLE
Attribute name carrying the RRD tool style.- See Also:
ISOLIKE
private static final java.time.format.DateTimeFormatter ISOLIKETimestamp format written into the XML, in UTC.DEFAULT_NAN_STRING
How NaN is written when no other form is given.writer
Where the XML is written.indent
Indentation of the element currently being written.openTags
timeFormatter
private final java.time.format.DateTimeFormatter timeFormatterTime formatterdoubleFormatter
Double formatter
Constructor Details
XmlWriter
private XmlWriter(PrintWriter writer, java.time.format.DateTimeFormatter timeFormatter, XmlWriter.DoubleFormater doubleFormatter) Creates a writer for one XML document.- Parameters:
writer- where the XML is writtentimeFormatter- how timestamps are writtendoubleFormatter- how numbers are written
XmlWriter
Creates XmlWriter with the specifiedOutputStreamto send XML code to.- Parameters:
stream-OutputStreamwhich receives XML code
XmlWriter
Creates XmlWriter with the specified output stream to send XML code to.- Parameters:
stream- Output stream which receives XML codeautoFlush- is the stream to be flushed automatically
XmlWriter
Creates XmlWriter with the specifiedPrintWriterto send XML code to.- Parameters:
stream-PrintWriterwhich receives XML code
Method Details
withTimeZone
withDoubleFormatter
Return a newXmlWriterthat will format time stamp using thisZoneId- Parameters:
doubleFormatter- the formatter the returned writer renders DS values with- Returns:
- a new writer sharing this one's stream, unused otherwise
startTag
closeTag
public void closeTag()Closes the corresponding XML tagwriteTag
writeTag
Writes <tag>value</tag> to output stream- Parameters:
tag- XML tag namevalue- value to be placed between<tag>and</tag>
writeTag
Writes <tag>value</tag> to output stream- Parameters:
tag- XML tag namevalue- value to be placed between<tag>and</tag>
writeTag
writeTag
Writes <tag>value</tag> to output stream- Parameters:
tag- XML tag namevalue- value to be placed between<tag>and</tag>
writeTag
Writes <tag>value</tag> to output stream- Parameters:
tag- XML tag namevalue- value to be placed between<tag>and</tag>
writeTag
writeTag
writeTag
flush
public void flush()Flushes the output streamwriteComment
Writes XML comment to output stream- Parameters:
comment- comment string
writeComment
public void writeComment(long timestamp) Writes a timestamp using the configuredDateTimeFormatteras an XML comment to output stream.- Parameters:
timestamp- the timestamp to write
formatTimestamp
Formats a timestamp using the configuredDateTimeFormatter.- Parameters:
timestamp- the timestamp to format- Returns:
- the formatted timestamp
escape
close
public void close()Flushes the underlying writer, then closes it.- Specified by:
closein interfaceAutoCloseable