Module bus.setting

Class TomlWriter

java.lang.Object
org.miaixz.bus.setting.metric.toml.TomlWriter

public class TomlWriter extends Object
A writer for generating TOML (Tom's Obvious, Minimal Language) data from a Map.

Supported date/time types for writing:

This writer supports bare keys consisting of A-Za-z0-9_-. Any other keys will be enclosed in double quotes.

Since:
Java 17+
Author:
Kimi Liu
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new TomlWriter with default parameters.
    TomlWriter(Writer writer, int indentSize, boolean indentWithSpaces)
    Creates a new TomlWriter with specified indentation parameters.
    TomlWriter(Writer writer, int indentSize, boolean indentWithSpaces, String lineSeparator)
    Creates a new TomlWriter with the specified parameters.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Closes the underlying writer, flushing it first.
    void
    Flushes the underlying writer.
    void
    Writes the specified data map to the writer in TOML format.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • TomlWriter

      public TomlWriter(Writer writer)
      Creates a new TomlWriter with default parameters. The system line separator is used. This is equivalent to TomlWriter(writer, 1, false, System.lineSeparator()).
      Parameters:
      writer - where to write the data
    • TomlWriter

      public TomlWriter(Writer writer, int indentSize, boolean indentWithSpaces)
      Creates a new TomlWriter with specified indentation parameters. The system line separator is used. This is equivalent to TomlWriter(writer, indentSize, indentWithSpaces, System.lineSeparator()).
      Parameters:
      writer - where to write the data
      indentSize - the number of characters for each indent level
      indentWithSpaces - true to indent with spaces, false to indent with tabs
    • TomlWriter

      public TomlWriter(Writer writer, int indentSize, boolean indentWithSpaces, String lineSeparator)
      Creates a new TomlWriter with the specified parameters.
      Parameters:
      writer - where to write the data
      indentSize - the number of characters for each indent level
      indentWithSpaces - true to indent with spaces, false to indent with tabs
      lineSeparator - the string to use for line breaks
  • Method Details

    • close

      public void close() throws IOException
      Closes the underlying writer, flushing it first.
      Throws:
      IOException - if an I/O error occurs
    • flush

      public void flush() throws IOException
      Flushes the underlying writer.
      Throws:
      IOException - if an I/O error occurs
    • write

      public void write(Map<String,Object> data) throws org.miaixz.bus.core.lang.exception.InternalException
      Writes the specified data map to the writer in TOML format.
      Parameters:
      data - the data to write
      Throws:
      org.miaixz.bus.core.lang.exception.InternalException - if an I/O error occurs during writing