Package org.snakeyaml.engine.v2.api
Class LoadSettingsBuilder
java.lang.Object
org.snakeyaml.engine.v2.api.LoadSettingsBuilder
Builder pattern implementation for LoadSettings
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
private boolean
private Integer
private int
private final Map
<SettingKey, Object> private IntFunction
<List<Object>> private IntFunction
<Map<Object, Object>> private IntFunction
<Set<Object>> private String
private int
private boolean
private Schema
private Map
<Tag, ConstructNode> private boolean
private UnaryOperator
<SpecVersion> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()
Build immutable LoadSettingssetAllowDuplicateKeys
(boolean allowDuplicateKeys) YAML 1.2 does require unique keys.setAllowRecursiveKeys
(boolean allowRecursiveKeys) Allow only non-recursive keys for maps and sets.setBufferSize
(Integer bufferSize) Buffer size for incoming data stream.setCodePointLimit
(int codePointLimit) The max amount of code points for every input YAML document in the stream.setCustomProperty
(SettingKey key, Object value) Provide a custom property to be used latersetDefaultList
(IntFunction<List<Object>> defaultList) Provide default List implementation.setDefaultMap
(IntFunction<Map<Object, Object>> defaultMap) Provide default Map implementation.setDefaultSet
(IntFunction<Set<Object>> defaultSet) Provide default Set implementation.setEnvConfig
(Optional<EnvConfig> envConfig) Define EnvConfig to parse EVN format.Label for the input data.setMaxAliasesForCollections
(int maxAliasesForCollections) Restrict the number of aliases for collection nodes to prevent Billion laughs attack.setParseComments
(boolean parseComments) Parse comments to the presentation tree (Node).Provide either recommended or custom schema instead of default *CoreSchema
These 3 are availableFailsafeSchema
,JsonSchema
,CoreSchema
.setTagConstructors
(Map<Tag, ConstructNode> tagConstructors) Provide constructors for the specified tags.setUseMarks
(boolean useMarks) Marks are only used for error messages.setVersionFunction
(UnaryOperator<SpecVersion> versionFunction) Manage YAML directive value which defines the version of the YAML specification.
-
Field Details
-
customProperties
-
label
-
tagConstructors
-
defaultList
-
defaultSet
-
defaultMap
-
versionFunction
-
bufferSize
-
allowDuplicateKeys
private boolean allowDuplicateKeys -
allowRecursiveKeys
private boolean allowRecursiveKeys -
parseComments
private boolean parseComments -
maxAliasesForCollections
private int maxAliasesForCollections -
useMarks
private boolean useMarks -
envConfig
-
codePointLimit
private int codePointLimit -
schema
-
-
Constructor Details
-
LoadSettingsBuilder
LoadSettingsBuilder()Create builder
-
-
Method Details
-
setLabel
Label for the input data. Can be used to improve the error message.- Parameters:
label
- - meaningful label to indicate the input source- Returns:
- the builder with the provided value
-
setTagConstructors
Provide constructors for the specified tags.- Parameters:
tagConstructors
- - the map from a Tag to its constructor- Returns:
- the builder with the provided value
-
setDefaultList
Provide default List implementation.ArrayList
is used if nothing provided.- Parameters:
defaultList
- - specified List implementation (as a function from init size)- Returns:
- the builder with the provided value
-
setDefaultSet
Provide default Set implementation.LinkedHashSet
is used if nothing provided.- Parameters:
defaultSet
- - specified Set implementation (as a function from init size)- Returns:
- the builder with the provided value
-
setDefaultMap
Provide default Map implementation.LinkedHashMap
is used if nothing provided.- Parameters:
defaultMap
- - specified Map implementation (as a function from init size)- Returns:
- the builder with the provided value
-
setBufferSize
Buffer size for incoming data stream. If the incoming stream is already buffered, then changing the buffer does not improve the performance- Parameters:
bufferSize
- - buffer size (in bytes) for input data- Returns:
- the builder with the provided value
-
setAllowDuplicateKeys
YAML 1.2 does require unique keys. To support the backwards compatibility it is possible to select what should happend when non-unique keys are detected.- Parameters:
allowDuplicateKeys
- - if true than the non-unique keys in a mapping are allowed (last key wins). False by default.- Returns:
- the builder with the provided value
-
setAllowRecursiveKeys
Allow only non-recursive keys for maps and sets. By default is it not allowed. Even though YAML allows to use anything as a key, it may cause unexpected issues when loading recursive structures.- Parameters:
allowRecursiveKeys
- - true to allow recursive structures as keys- Returns:
- the builder with the provided value
-
setMaxAliasesForCollections
Restrict the number of aliases for collection nodes to prevent Billion laughs attack. The purpose of this setting is to force SnakeYAML to fail before a lot of CPU and memory resources are allocated for the parser. Aliases for scalar nodes do not count because they do not grow exponentially.- Parameters:
maxAliasesForCollections
- - max number of aliases. More then 50 might be very dangerous. Default is 50- Returns:
- the builder with the provided value
-
setUseMarks
Marks are only used for error messages. But they requires a lot of memory. True by default.- Parameters:
useMarks
- - use false to save resources but use less informative error messages (no line and context)- Returns:
- the builder with the provided value
-
setVersionFunction
Manage YAML directive value which defines the version of the YAML specification. This parser supports YAML 1.2 but it can parse most of YAML 1.1 and YAML 1.0This function allows to control the version management. For instance if the document contains old version the parser can be adapted to compensate the problem. Or it can fail to indicate that the incoming version is not supported.
- Parameters:
versionFunction
- - define the way to manage the YAML version. By default, 1.* versions are accepted and treated as YAML 1.2. Other versions fail to parse (YamlVersionException is thown)- Returns:
- the builder with the provided value
-
setEnvConfig
Define EnvConfig to parse EVN format. If not set explicitly the variable substitution is not applied- Parameters:
envConfig
- - non-empty configuration to substitute variables- Returns:
- the builder with the provided value
- See Also:
-
setCustomProperty
Provide a custom property to be used later- Parameters:
key
- - the keyvalue
- - the value behind the key- Returns:
- the builder with the provided value
-
setParseComments
Parse comments to the presentation tree (Node). False by default- Parameters:
parseComments
- - use true to parse comments to the presentation tree (Node)- Returns:
- the builder with the provided value
-
setCodePointLimit
The max amount of code points for every input YAML document in the stream. Please be aware that byte limit depends on the encoding.- Parameters:
codePointLimit
- - the max allowed size of a single YAML document in a stream- Returns:
- the builder with the provided value
-
setSchema
Provide either recommended or custom schema instead of default *CoreSchema
These 3 are availableFailsafeSchema
,JsonSchema
,CoreSchema
.- Parameters:
schema
- to be used for parsing- Returns:
- the builder with the provided value
-
build
Build immutable LoadSettings- Returns:
- immutable LoadSettings
-