Class LoadSettingsBuilder

java.lang.Object
org.snakeyaml.engine.v2.api.LoadSettingsBuilder

public final class LoadSettingsBuilder extends Object
Builder pattern implementation for LoadSettings
  • Field Details

    • customProperties

      private final Map<SettingKey,Object> customProperties
    • label

      private String label
    • tagConstructors

      private Map<Tag,ConstructNode> tagConstructors
    • defaultList

      private IntFunction<List<Object>> defaultList
    • defaultSet

      private IntFunction<Set<Object>> defaultSet
    • defaultMap

      private IntFunction<Map<Object,Object>> defaultMap
    • versionFunction

      private UnaryOperator<SpecVersion> versionFunction
    • bufferSize

      private Integer bufferSize
    • allowDuplicateKeys

      private boolean allowDuplicateKeys
    • allowRecursiveKeys

      private boolean allowRecursiveKeys
    • parseComments

      private boolean parseComments
    • maxAliasesForCollections

      private int maxAliasesForCollections
    • useMarks

      private boolean useMarks
    • envConfig

      private Optional<EnvConfig> envConfig
    • codePointLimit

      private int codePointLimit
    • schema

      private Schema schema
  • Constructor Details

    • LoadSettingsBuilder

      LoadSettingsBuilder()
      Create builder
  • Method Details

    • setLabel

      public LoadSettingsBuilder setLabel(String label)
      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

      public LoadSettingsBuilder setTagConstructors(Map<Tag,ConstructNode> tagConstructors)
      Provide constructors for the specified tags.
      Parameters:
      tagConstructors - - the map from a Tag to its constructor
      Returns:
      the builder with the provided value
    • setDefaultList

      public LoadSettingsBuilder setDefaultList(IntFunction<List<Object>> defaultList)
      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

      public LoadSettingsBuilder setDefaultSet(IntFunction<Set<Object>> defaultSet)
      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

      public LoadSettingsBuilder setDefaultMap(IntFunction<Map<Object,Object>> defaultMap)
      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

      public LoadSettingsBuilder setBufferSize(Integer bufferSize)
      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

      public LoadSettingsBuilder setAllowDuplicateKeys(boolean allowDuplicateKeys)
      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

      public LoadSettingsBuilder setAllowRecursiveKeys(boolean allowRecursiveKeys)
      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

      public LoadSettingsBuilder setMaxAliasesForCollections(int maxAliasesForCollections)
      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

      public LoadSettingsBuilder setUseMarks(boolean useMarks)
      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

      public LoadSettingsBuilder setVersionFunction(UnaryOperator<SpecVersion> versionFunction)
      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.0

      This 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

      public LoadSettingsBuilder setEnvConfig(Optional<EnvConfig> envConfig)
      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

      public LoadSettingsBuilder setCustomProperty(SettingKey key, Object value)
      Provide a custom property to be used later
      Parameters:
      key - - the key
      value - - the value behind the key
      Returns:
      the builder with the provided value
    • setParseComments

      public LoadSettingsBuilder setParseComments(boolean parseComments)
      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

      public LoadSettingsBuilder setCodePointLimit(int codePointLimit)
      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

      public LoadSettingsBuilder setSchema(Schema schema)
      Provide either recommended or custom schema instead of default * CoreSchema These 3 are available FailsafeSchema, JsonSchema, CoreSchema.
      Parameters:
      schema - to be used for parsing
      Returns:
      the builder with the provided value
    • build

      public LoadSettings build()
      Build immutable LoadSettings
      Returns:
      immutable LoadSettings