com.appcrossings.config.processor.YamlProcessor Maven / Gradle / Ivy
package com.appcrossings.config.processor;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.yaml.snakeyaml.Yaml;
import com.appcrossings.config.util.StringUtils;
public class YamlProcessor {
public static Map asProperties(InputStream stream) {
Yaml yaml = new Yaml();
final Map properties = new HashMap<>();
LinkedHashMap map = (LinkedHashMap) yaml.load(stream);
StringBuilder builder = new StringBuilder();
recurse(map, builder, properties);
return properties;
}
public static Map asProperties(byte[] stream) {
Yaml yaml = new Yaml();
final Map properties = new HashMap<>();
LinkedHashMap map = (LinkedHashMap) yaml.load(new ByteArrayInputStream(stream));
StringBuilder builder = new StringBuilder();
recurse(map, builder, properties);
return properties;
}
public static boolean isYamlFile(String path) {
assert StringUtils.hasText(path) : "Path was null or empty";
return (path.toLowerCase().endsWith(".yaml") || path.toLowerCase().endsWith(".yml"));
}
private static void recurse(List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy