org.yaml.snakeyaml.LoaderOptions Java Examples

The following examples show how to use org.yaml.snakeyaml.LoaderOptions. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: YamlUtils.java    From configuration-as-code-plugin with MIT License 6 votes vote down vote up
public static Node read(YamlSource source, Reader reader, ConfigurationContext context) throws IOException {
    LoaderOptions loaderOptions = new LoaderOptions();
    loaderOptions.setMaxAliasesForCollections(context.getYamlMaxAliasesForCollections());
    Composer composer = new Composer(
        new ParserImpl(new StreamReaderWithSource(source, reader)),
        new Resolver(),
        loaderOptions);
    try {
        return composer.getSingleNode();
    } catch (YAMLException e) {
        if (e.getMessage().startsWith("Number of aliases for non-scalar nodes exceeds the specified max")) {
            throw new ConfiguratorException(String.format(
                "%s%nYou can increase the maximum by setting an environment variable or property%n  ENV: %s=\"100\"%n  PROPERTY: -D%s=\"100\"",
                e.getMessage(), ConfigurationContext.CASC_YAML_MAX_ALIASES_ENV,
                ConfigurationContext.CASC_YAML_MAX_ALIASES_PROPERTY));
        }
        throw e;
    }
}
 
Example #2
Source File: YAMLConfiguration.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
@Override
public void read(final Reader in) throws ConfigurationException
{
    try
    {
        final Yaml yaml = createYamlForReading(new LoaderOptions());
        final Map<String, Object> map = (Map) yaml.load(in);
        load(map);
    }
    catch (final Exception e)
    {
        rethrowException(e);
    }
}
 
Example #3
Source File: YAMLConfiguration.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
public void read(final Reader in, final LoaderOptions options)
        throws ConfigurationException
{
    try
    {
        final Yaml yaml = createYamlForReading(options);
        final Map<String, Object> map = (Map) yaml.load(in);
        load(map);
    }
    catch (final Exception e)
    {
        rethrowException(e);
    }
}
 
Example #4
Source File: YAMLConfiguration.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Loads the configuration from the given input stream.
 *
 * @param in the input stream
 * @throws ConfigurationException if an error occurs
 */
@Override
public void read(final InputStream in) throws ConfigurationException
{
    try
    {
        final Yaml yaml = createYamlForReading(new LoaderOptions());
        final Map<String, Object> map = (Map) yaml.load(in);
        load(map);
    }
    catch (final Exception e)
    {
        rethrowException(e);
    }
}
 
Example #5
Source File: YAMLConfiguration.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
public void read(final InputStream in, final LoaderOptions options)
        throws ConfigurationException
{
    try
    {
        final Yaml yaml = createYamlForReading(options);
        final Map<String, Object> map = (Map) yaml.load(in);
        load(map);
    }
    catch (final Exception e)
    {
        rethrowException(e);
    }
}
 
Example #6
Source File: AbstractUserAgentAnalyzerDirect.java    From yauaa with Apache License 2.0 4 votes vote down vote up
private Yaml createYaml() {
    final LoaderOptions yamlLoaderOptions = new LoaderOptions();
    yamlLoaderOptions.setMaxAliasesForCollections(100); // We use this many in the hacker/sql injection config.
    return new Yaml(yamlLoaderOptions);
}
 
Example #7
Source File: YamlParser.java    From night-config with GNU Lesser General Public License v3.0 4 votes vote down vote up
public YamlParser(LoaderOptions options) {
	this(new Yaml(options));
}
 
Example #8
Source File: YamlProcessor.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Create the {@link Yaml} instance to use.
 * <p>The default implementation sets the "allowDuplicateKeys" flag to {@code false},
 * enabling built-in duplicate key handling in SnakeYAML 1.18+.
 * @see LoaderOptions#setAllowDuplicateKeys(boolean)
 */
protected Yaml createYaml() {
	LoaderOptions options = new LoaderOptions();
	options.setAllowDuplicateKeys(false);
	return new Yaml(options);
}
 
Example #9
Source File: YamlProcessor.java    From java-technology-stack with MIT License 1 votes vote down vote up
/**
 * Create the {@link Yaml} instance to use.
 * <p>The default implementation sets the "allowDuplicateKeys" flag to {@code false},
 * enabling built-in duplicate key handling in SnakeYAML 1.18+.
 * @see LoaderOptions#setAllowDuplicateKeys(boolean)
 */
protected Yaml createYaml() {
	LoaderOptions options = new LoaderOptions();
	options.setAllowDuplicateKeys(false);
	return new Yaml(options);
}
 
Example #10
Source File: YAMLConfiguration.java    From commons-configuration with Apache License 2.0 1 votes vote down vote up
/**
 * Creates a {@code Yaml} object for reading a Yaml file. The object is
 * configured with some default settings.
 *
 * @param options options for loading the file
 * @return the {@code Yaml} instance for loading a file
 */
private static Yaml createYamlForReading(LoaderOptions options)
{
    return new Yaml(createClassLoadingDisablingConstructor(), new Representer(), new DumperOptions(), options);
}