java.lang.Object
com.moandjiezana.toml.TomlWriter
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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionWrite an Object into TOML String.voidWrite an Object in TOML to aFile.voidwrite(Object from, OutputStream target) Write an Object in TOML to aOutputStream.voidWrite an Object in TOML to aWriter.
-
Constructor Details
-
TomlWriter
public TomlWriter()Creates a TomlWriter instance.
-
-
Method Details
-
write
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
Write 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:
IOException- if any file operations fail
-
write
Write 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:
IOException- if target.write() fails
-
write
Write 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:
IOException- if target.write() failsIllegalArgumentException- if from is of an invalid type
-