cz.jalasoft.util.configuration.provider.HoconConfigProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of JalasoftUtils Show documentation
Show all versions of JalasoftUtils Show documentation
A collection of utility classes that might be useful.
The newest version!
package cz.jalasoft.util.configuration.provider;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import cz.jalasoft.util.configuration.source.ConfigSource;
import java.io.IOException;
import java.io.Reader;
/**
* @author Honza Lastovicka ([email protected])
* @since 2016-07-27.
*/
public final class HoconConfigProvider implements ConfigProvider {
private Config config;
public HoconConfigProvider() {
checkTypeSafeConfingOnClasspath();
}
private void checkTypeSafeConfingOnClasspath() {
try {
Class.forName("com.typesafe.config.Config");
} catch (ClassNotFoundException exc) {
throw new IllegalStateException("Cannot load TypeSafeConfig library as a source of hocon configuration infrastructure.");
}
}
@Override
public void reload(ConfigSource source) throws IOException {
try (Reader input = source.load()) {
config = ConfigFactory.parseReader(input);
}
}
@Override
public String readProperty(String key) {
if (config == null) {
throw new IllegalStateException("First call reload()");
}
return config.getString(key);
}
}