Class TomlWriteOptions
TomlTable.toToml(TomlWriteOptions) and TomlArray.toToml(TomlWriteOptions)
write TOML.
keep(Keep) sets how much of the existing structure and format of a parsed document is kept.
TomlWriteOptions.Keep.LAYOUT, the default, keeps the layout: a parsed document is written from the text it was parsed from,
and only what the editing API changed is written anew. TomlWriteOptions.Keep.NOTATION keeps the notation - the form each key,
value and table was written in, the order of lines and sections and the comments - while whitespace, indentation,
blank lines and the layout of arrays and inline tables come from these options. TomlWriteOptions.Keep.NOTHING keeps nothing,
and writes the whole document in the default style.
Each value falls back to the next where there is nothing to keep: a line written anew is written as
TomlWriteOptions.Keep.NOTATION writes it, and a table or array with no notation to keep - one built through the editing API,
or read from a document parsed with TomlParseOptions.withoutSource() - is written as TomlWriteOptions.Keep.NOTHING
writes it, in the default style.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumHow much of the existing document structure and format is kept. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default maximum line width: 80. -
Method Summary
Modifier and TypeMethodDescriptionbooleanWhether a blank line separates a header from the header of a table within it that directly follows it.static TomlWriteOptionsdefaults()The default options:TomlWriteOptions.Keep.LAYOUT, no indentation, a maximum line width of 80, no line separator of their own, so that lines end with the platform's,System.lineSeparator(), and output written forTomlVersion.LATEST.booleanWhether the entries of a table are indented like its header.booleaninthashCode()intindent()The number of spaces to indent per level of table nesting.keep()How much of the existing document structure and format is kept.keep(TomlWriteOptions.Keep keep) Create a copy of these options that keeps a different amount of the existing document structure and format.The line separator written at the end of each line.intThe widest a line may be for an array to be written on one line.booleanWhether an array written on one line has a space inside each bracket.toString()version()The version of TOML the output is written for,TomlVersion.LATESTby default.withBlankLineBetweenNestedHeaders(boolean blankLine) Create a copy of these options that does or does not write a blank line between a table header and the header of a table within it that directly follows it.withEntriesAlignedWithHeaders(boolean aligned) Create a copy of these options that indents the entries of a table like its header, or one level beyond it.withIndent(int spaces) Create a copy of these options that indents nested tables.withLineSeparator(String separator) Create a copy of these options that ends each line with a different line separator.withMaxLineWidth(int columns) Create a copy of these options with a different maximum line width.withSpaceInsideArrays(boolean spaced) Create a copy of these options that writes an array on one line with a space inside each bracket,[ 1, 2 ], or without,[1, 2].withVersion(TomlVersion version) Create a copy of these options that writes for a different version of TOML.
-
Field Details
-
DEFAULT_MAX_LINE_WIDTH
public static final int DEFAULT_MAX_LINE_WIDTHThe default maximum line width: 80.- See Also:
-
-
Method Details
-
defaults
The default options:TomlWriteOptions.Keep.LAYOUT, no indentation, a maximum line width of 80, no line separator of their own, so that lines end with the platform's,System.lineSeparator(), and output written forTomlVersion.LATEST.- Returns:
- The default options.
-
keep
Create a copy of these options that keeps a different amount of the existing document structure and format.- Parameters:
keep- How much of the existing document structure and format to keep.- Returns:
- A new set of options with the given amount to keep.
-
withIndent
Create a copy of these options that indents nested tables.A header whose path has
nkeys is indented by(n - 1) * spaces, and the entries of a table whose path hasnkeys byn * spaces. The entries of the root table are not indented, and the path of a table in an array of tables is the path of the array. For example, with an indent of 2:title = "Example" [server] host = "localhost" [server.tls] enabled = true [[products]] sku = 1withEntriesAlignedWithHeaders(boolean)indents the entries of a table like its header instead.Regardless of the indent, the elements of a multi-line array are indented two spaces beyond the line the array starts on.
- Parameters:
spaces- The number of spaces to indent per level of table nesting. Must not be negative.- Returns:
- A new set of options with the given indent.
- Throws:
IllegalArgumentException- Ifspacesis negative.
-
withEntriesAlignedWithHeaders
Create a copy of these options that indents the entries of a table like its header, or one level beyond it.With entries aligned, the entries of a table whose path has
nkeys are indented by(n - 1) * spaces, the same as its header, rather than byn * spaces. For example, with an indent of 2:title = "Example" [server] host = "localhost" [server.tls] enabled = true [[products]] sku = 1The default is
false, which indents entries one level beyond their header; seewithIndent(int).- Parameters:
aligned- Whether the entries of a table are indented like its header.- Returns:
- A new set of options with the given alignment.
-
withLineSeparator
Create a copy of these options that ends each line with a different line separator.The separator is also used for the line breaks inside a multi-line basic string, written for a string value that contains a newline.
- Parameters:
separator- The line separator:"\n"or"\r\n", the only newlines that TOML allows.- Returns:
- A new set of options with the given line separator.
- Throws:
IllegalArgumentException- Ifseparatoris neither"\n"nor"\r\n".
-
withMaxLineWidth
Create a copy of these options with a different maximum line width.An array is written on one line if that whole line fits within the maximum width, and otherwise with each element on its own line. The width of a line is counted in code points, and includes its indentation, the key before the array, and the comma after an element of an enclosing multi-line array.
When writing TOML 1.1.0, an inline table is written the same way, with each entry on its own line. When writing TOML 1.0.0, an inline table is never split, and everything inside one stays on one line; see
withVersion(TomlVersion).Lines can still be wider than the maximum: a long key or string is never split, nor is an inline table when writing TOML 1.0.0. With a maximum width of
0, every non-empty array and inline table is written over multiple lines, except, when writing TOML 1.0.0, an inline table and everything inside one.- Parameters:
columns- The widest a line may be, in code points, for an array to be written on one line. Must not be negative.- Returns:
- A new set of options with the given maximum line width.
- Throws:
IllegalArgumentException- Ifcolumnsis negative.
-
withSpaceInsideArrays
Create a copy of these options that writes an array on one line with a space inside each bracket,[ 1, 2 ], or without,[1, 2].The spaces count towards the width of the line, see
withMaxLineWidth(int). An empty array is written[]either way, and an array written over several lines is not affected. The default isfalse.- Parameters:
spaced- Whether an array written on one line has a space inside each bracket.- Returns:
- A new set of options with the given array spacing.
-
withBlankLineBetweenNestedHeaders
Create a copy of these options that does or does not write a blank line between a table header and the header of a table within it that directly follows it.A header is written with a blank line above it. Without that blank line between nested headers, a header that directly follows the header of a table containing it, with no entry or unattached comment between them, is written on the next line:
[servers] [servers.alpha] ip = "10.0.0.1" [servers.beta] ip = "10.0.0.2"The blank line is left out only where these options lay out the header: in
TomlWriteOptions.Keep.LAYOUT, a header the document wrote keeps the blank lines it had. The default istrue.- Parameters:
blankLine- Whether a blank line separates a header from the header of a table within it that directly follows it.- Returns:
- A new set of options with the given blank line setting.
-
keep
How much of the existing document structure and format is kept.- Returns:
- How much of the existing document structure and format is kept.
- See Also:
-
withVersion
Create a copy of these options that writes for a different version of TOML.The version decides how an inline table that does not fit within the maximum line width is written. When writing TOML 1.1.0, which allows line breaks inside an inline table, such a table is written over several lines, with each entry on its own line, as an array is. When writing TOML 1.0.0, which allows no line break inside an inline table, an inline table is written on one line regardless of its width. The default is
TomlVersion.LATEST.An inline table holding a comment can only be written over several lines, since a comment ends at a line break, so writing one for TOML 1.0.0 throws
IllegalArgumentException.Text copied from a document (a line kept as it was read, or the literal a key or value was written as) is copied only for a version that allows it. Writing for TOML 1.0.0 throws
IllegalArgumentExceptionwhere it would copy a construct of TOML 1.1.0: an escape sequence\eor\xHH, a time without seconds, or a line break or trailing comma inside an inline table, whether the text comes from the document being written, from a value made withTomlValue.parse(String), or from a value copied out of another document. A value replaced or removed through the editing API is not copied, andTomlWriteOptions.Keep.NOTHINGcopies no text.- Parameters:
version- The version of TOML to write for.- Returns:
- A new set of options with the given version.
- See Also:
-
indent
public int indent()The number of spaces to indent per level of table nesting.- Returns:
- The number of spaces to indent per level of table nesting.
- See Also:
-
entriesAlignedWithHeaders
public boolean entriesAlignedWithHeaders()Whether the entries of a table are indented like its header.- Returns:
trueif the entries of a table are indented like its header,falseif one level beyond it.- See Also:
-
spaceInsideArrays
public boolean spaceInsideArrays()Whether an array written on one line has a space inside each bracket.- Returns:
trueif an array written on one line has a space inside each bracket.- See Also:
-
blankLineBetweenNestedHeaders
public boolean blankLineBetweenNestedHeaders()Whether a blank line separates a header from the header of a table within it that directly follows it.- Returns:
trueif a blank line separates the two headers.- See Also:
-
lineSeparator
The line separator written at the end of each line.- Returns:
- The line separator these options ask for, or
System.lineSeparator()if they ask for none. - See Also:
-
maxLineWidth
public int maxLineWidth()The widest a line may be for an array to be written on one line.- Returns:
- The maximum line width, in code points.
- See Also:
-
version
The version of TOML the output is written for,TomlVersion.LATESTby default.- Returns:
- The version of TOML the output is written for.
- See Also:
-
equals
-
hashCode
public int hashCode() -
toString
-