Module toml4j

Class TomlWriter

java.lang.Object
com.moandjiezana.toml.TomlWriter

public class TomlWriter extends Object

Converts Objects to TOML

An input Object can comprise arbitrarily nested combinations of Java primitive types, other Objects, Maps, Lists, and Arrays. Objects and Maps are output to TOML tables, and Lists and Array to TOML arrays.

Example usage:


 class AClass {
   int anInt = 1;
   int[] anArray = { 2, 3 };
 }

 String tomlString = new TomlWriter().write(new AClass());
 
  • Constructor Details

    • TomlWriter

      public TomlWriter()
      Creates a TomlWriter instance.
  • Method Details

    • write

      public String write(Object from)
      Write an Object into TOML String.
      Parameters:
      from - the object to be written
      Returns:
      a string containing the TOML representation of the given Object
    • write

      public void write(Object from, File target) throws IOException
      Write an Object in TOML to a File. Output is encoded as UTF-8.
      Parameters:
      from - the object to be written
      target - the File to which the TOML will be written
      Throws:
      IOException - if any file operations fail
    • write

      public void write(Object from, OutputStream target) throws IOException
      Write an Object in TOML to a OutputStream. Output is encoded as UTF-8.
      Parameters:
      from - the object to be written
      target - the OutputStream to which the TOML will be written. The stream is NOT closed after being written to.
      Throws:
      IOException - if target.write() fails
    • write

      public void write(Object from, Writer target) throws IOException
      Write an Object in TOML to a Writer. You MUST ensure that the Writers's encoding is set to UTF-8 for the TOML to be valid.
      Parameters:
      from - the object to be written. Can be a Map or a custom type. Must not be null.
      target - the Writer to which TOML will be written. The Writer is not closed.
      Throws:
      IOException - if target.write() fails
      IllegalArgumentException - if from is of an invalid type