All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.resource4j.extras.config.ConfigParser Maven / Gradle / Ivy

There is a newer version: 3.3.1
Show newest version
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