prompto.utils.YamlUtils Maven / Gradle / Ivy
The newest version!
package prompto.utils;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.Map;
import com.esotericsoftware.yamlbeans.YamlReader;
public abstract class YamlUtils {
static final Logger logger = new Logger();
public static Map readResource(String resource) throws IOException {
return readResource(()->Thread.currentThread().getContextClassLoader().getResourceAsStream(resource));
}
@SuppressWarnings("unchecked")
public static Map readResource(InputStreamSupplier supplier) throws IOException {
try(InputStream input = supplier.getInputStream()) {
try(Reader reader = new InputStreamReader(input)) {
YamlReader yaml = new YamlReader(reader);
Object read = yaml.read();
if(read instanceof Map)
return (Map)read;
else {
logger.error(()->"Expected Map got: " + read.getClass().getName());
return null;
}
}
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy