Package de.thelooter.toml
Class TomlWriter
- java.lang.Object
-
- de.thelooter.toml.TomlWriter
-
public class TomlWriter extends java.lang.ObjectConverts Objects to TOML
An input Object can comprise arbitrarily nested combinations of Java primitive types, other
Objects,Maps,Lists, and Arrays.Objects andMaps are output to TOML tables, andLists 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 classTomlWriter.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.Stringwrite(java.lang.Object from)Write an Object into TOML String.voidwrite(java.lang.Object from, java.io.File target)Write an Object in TOML to aFile.voidwrite(java.lang.Object from, java.io.OutputStream target)Write an Object in TOML to aOutputStream.voidwrite(java.lang.Object from, java.io.Writer target)Write an Object in TOML to aWriter.
-
-
-
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.IOExceptionWrite an Object in TOML to aFile. Output is encoded as UTF-8.- Parameters:
from- the object to be writtentarget- 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.IOExceptionWrite an Object in TOML to aOutputStream. Output is encoded as UTF-8.- Parameters:
from- the object to be writtentarget- 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.IOExceptionWrite an Object in TOML to aWriter. You MUST ensure that theWriters'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() failsjava.lang.IllegalArgumentException- if from is of an invalid type
-
-