
com.github.resource4j.extras.config.ConfigParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of resource4j-extras Show documentation
Show all versions of resource4j-extras Show documentation
Integration of Resource4J with various parsers and other addons.
package com.github.resource4j.extras.config;
import java.io.IOException;
import java.io.InputStreamReader;
import com.github.resource4j.ResourceObject;
import com.github.resource4j.ResourceObjectException;
import com.github.resource4j.objects.parsers.AbstractValueParser;
import com.github.resource4j.objects.parsers.ResourceObjectFormatException;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigException;
import com.typesafe.config.ConfigFactory;
import com.typesafe.config.ConfigParseOptions;
import com.typesafe.config.ConfigSyntax;
@SuppressWarnings("WeakerAccess")
public class ConfigParser extends AbstractValueParser {
private ConfigParseOptions options;
public static ConfigParser config() {
return new ConfigParser();
}
public static ConfigParser config(ConfigParseOptions options) {
return new ConfigParser(options);
}
public ConfigParser() {
options = ConfigParseOptions.defaults()
.setSyntax(ConfigSyntax.CONF)
.setAllowMissing(false);
}
public ConfigParser(ConfigParseOptions options) {
super();
this.options = options;
}
@Override
protected Config parse(ResourceObject file) throws IOException,
ResourceObjectException {
try {
InputStreamReader reader = new InputStreamReader(file.asStream());
return ConfigFactory.parseReader(reader, options);
} catch (ConfigException e) {
throw new ResourceObjectFormatException(file, e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy