Class TomlWriter


  • public class TomlWriter
    extends java.lang.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());
     
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  TomlWriter.Builder  
    • Constructor Summary

      Constructors 
      Constructor Description
      TomlWriter()
      Creates a TomlWriter instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String write​(java.lang.Object from)
      Write an Object into TOML String.
      void write​(java.lang.Object from, java.io.File target)
      Write an Object in TOML to a File.
      void write​(java.lang.Object from, java.io.OutputStream target)
      Write an Object in TOML to a OutputStream.
      void write​(java.lang.Object from, java.io.Writer target)
      Write an Object in TOML to a Writer.
      • Methods inherited from class java.lang.Object

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

      • TomlWriter

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

      • write

        public java.lang.String write​(java.lang.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​(java.lang.Object from,
                          java.io.File target)
                   throws java.io.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:
        java.io.IOException - if any file operations fail
      • write

        public void write​(java.lang.Object from,
                          java.io.OutputStream target)
                   throws java.io.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:
        java.io.IOException - if target.write() fails
      • write

        public void write​(java.lang.Object from,
                          java.io.Writer target)
                   throws java.io.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:
        java.io.IOException - if target.write() fails
        java.lang.IllegalArgumentException - if from is of an invalid type