org.rrd4j.core

## Class XmlWriter

- java.lang.Object
- - org.rrd4j.core.XmlWriter

- All Implemented Interfaces:
    AutoCloseable

      public class XmlWriter
      extends Object
      implements AutoCloseable

  Extremely simple utility class used to create XML documents.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static interface` | `XmlWriter.DoubleFormater` Functional interface for formatting double values in XML output.

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `(package private) static String` | `INDENT_STR`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `XmlWriter(OutputStream stream)` Creates XmlWriter with the specified `OutputStream` to 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 specified `PrintWriter` to send XML code to.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()`
    `void` | `closeTag()` Closes the corresponding XML tag
    `void` | `flush()` Flushes the output stream
    `String` | `formatTimestamp(long timestamp)` Formats a timestamp using the configured `DateTimeFormatter`.
    `void` | `startTag(String tag)` Opens XML tag
    `XmlWriter` | `withDoubleFormatter(XmlWriter.DoubleFormater doubleFormatter)` Return a new `XmlWriter` that will format time stamp using this `ZoneId`
    `XmlWriter` | `withTimeZone(java.time.ZoneId zid)` Return a new `XmlWriter` that will format time stamp as ISO 8601 with this explicit time zone `ZoneId`
    `void` | `writeComment(long timestamp)` Writes a timestamp using the configured `DateTimeFormatter` as an XML comment to output stream.
    `void` | `writeComment(Object comment)` Writes XML comment to output stream
    `void` | `writeTag(String tag, boolean value)` Writes <tag>value</tag> to output stream
    `void` | `writeTag(String tag, Color value)` Writes <tag>value</tag> to output stream
    `void` | `writeTag(String tag, double value)` Writes <tag>value</tag> to output stream
    `void` | `writeTag(String tag, double value, String nanString)` Writes <tag>value</tag> to output stream
    `void` | `writeTag(String tag, File value)` Writes <tag>value</tag> to output stream
    `void` | `writeTag(String tag, Font value)` Writes <tag>value</tag> to output stream
    `void` | `writeTag(String tag, int value)` Writes <tag>value</tag> to output stream
    `void` | `writeTag(String tag, long value)` Writes <tag>value</tag> to output stream
    `void` | `writeTag(String tag, Object value)` Writes <tag>value</tag> to output stream

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### INDENT_STR

          static final String INDENT_STR

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### XmlWriter

          public XmlWriter(OutputStream stream)

      Creates XmlWriter with the specified `OutputStream` to send XML code to.
      Parameters:
        `stream` - `OutputStream` which receives XML code

    - #### XmlWriter

          public XmlWriter(OutputStream stream,
                           boolean autoFlush)

      Creates XmlWriter with the specified output stream to send XML code to.
      Parameters:
        `stream` - Output stream which receives XML code
        `autoFlush` - is the stream to be flushed automatically

    - #### XmlWriter

          public XmlWriter(PrintWriter stream)

      Creates XmlWriter with the specified `PrintWriter` to send XML code to.
      Parameters:
        `stream` - `PrintWriter` which receives XML code

  - ### Method Detail

    - #### close

          public void close()

      Specified by:
        `close` in interface `AutoCloseable`

    - #### closeTag

          public void closeTag()

      Closes the corresponding XML tag

    - #### flush

          public void flush()

      Flushes the output stream

    - #### formatTimestamp

          public String formatTimestamp(long timestamp)

      Formats a timestamp using the configured `DateTimeFormatter`.
      Parameters:
        `timestamp` - the timestamp to format
      Returns:
        the formatted timestamp

    - #### startTag

          public void startTag(String tag)

      Opens XML tag
      Parameters:
        `tag` - XML tag name

    - #### withDoubleFormatter

          public XmlWriter withDoubleFormatter(XmlWriter.DoubleFormater doubleFormatter)

      Return a new `XmlWriter` that will format time stamp using this `ZoneId`
      Parameters:
        `doubleFormatter` -
      Returns:
        the XmlWriter

    - #### withTimeZone

          public XmlWriter withTimeZone(java.time.ZoneId zid)

      Return a new `XmlWriter` that will format time stamp as ISO 8601 with this explicit time zone `ZoneId`
      Parameters:
        `zid` -
      Returns:
        the XmlWriter

    - #### writeComment

          public void writeComment(long timestamp)

      Writes a timestamp using the configured `DateTimeFormatter` as an XML comment to output stream.
      Parameters:
        `timestamp` - the timestamp to write

    - #### writeComment

          public void writeComment(Object comment)

      Writes XML comment to output stream
      Parameters:
        `comment` - comment string

    - #### writeTag

          public void writeTag(String tag,
                               boolean value)

      Writes <tag>value</tag> to output stream
      Parameters:
        `tag` - XML tag name
        `value` - value to be placed between `<tag>` and `</tag>`

    - #### writeTag

          public void writeTag(String tag,
                               Color value)

      Writes <tag>value</tag> to output stream
      Parameters:
        `tag` - XML tag name
        `value` - value to be placed between `<tag>` and `</tag>`

    - #### writeTag

          public void writeTag(String tag,
                               double value)

      Writes <tag>value</tag> to output stream
      Parameters:
        `tag` - XML tag name
        `value` - value to be placed between `<tag>` and `</tag>`

    - #### writeTag

          public void writeTag(String tag,
                               double value,
                               String nanString)

      Writes <tag>value</tag> to output stream
      Parameters:
        `tag` - XML tag name
        `value` - value to be placed between `<tag>` and `</tag>`
        `nanString` - a `String` object.

    - #### writeTag

          public void writeTag(String tag,
                               File value)

      Writes <tag>value</tag> to output stream
      Parameters:
        `tag` - XML tag name
        `value` - value to be placed between `<tag>` and `</tag>`

    - #### writeTag

          public void writeTag(String tag,
                               Font value)

      Writes <tag>value</tag> to output stream
      Parameters:
        `tag` - XML tag name
        `value` - value to be placed between `<tag>` and `</tag>`

    - #### writeTag

          public void writeTag(String tag,
                               int value)

      Writes <tag>value</tag> to output stream
      Parameters:
        `tag` - XML tag name
        `value` - value to be placed between `<tag>` and `</tag>`

    - #### writeTag

          public void writeTag(String tag,
                               long value)

      Writes <tag>value</tag> to output stream
      Parameters:
        `tag` - XML tag name
        `value` - value to be placed between `<tag>` and `</tag>`

    - #### writeTag

          public void writeTag(String tag,
                               Object value)

      Writes <tag>value</tag> to output stream
      Parameters:
        `tag` - XML tag name
        `value` - value to be placed between `<tag>` and `</tag>`