use of com.esotericsoftware.yamlbeans.YamlReader in project yamlbeans by EsotericSoftware.
the class YamlEnumTest method read.
public void read(String string) throws IOException {
YamlReader reader = new YamlReader(string);
reader.read(TestObject.class);
reader.close();
}
use of com.esotericsoftware.yamlbeans.YamlReader in project StreetComplete by westnordost.
the class CreditsFragment method readTranslators.
private List<Map.Entry<String, String>> readTranslators() {
try {
InputStream is = getResources().openRawResource(R.raw.credits_translations);
YamlReader reader = new YamlReader(new InputStreamReader(is));
Map yml = (Map) reader.read();
List<Map.Entry<String, String>> result = new ArrayList<>();
for (Object e : yml.entrySet()) {
result.add((Map.Entry<String, String>) e);
}
Collections.sort(result, (o1, o2) -> o1.getKey().compareTo(o2.getKey()));
return result;
} catch (YamlException e) {
throw new RuntimeException(e);
}
}
use of com.esotericsoftware.yamlbeans.YamlReader in project StreetComplete by westnordost.
the class CountryInfos method loadCountryInfo.
private CountryInfo loadCountryInfo(String countryCodeIso3166) throws IOException {
String filename = countryCodeIso3166 + ".yml";
InputStream is = null;
try {
is = assetManager.open(BASEPATH + File.separator + filename);
Reader reader = new InputStreamReader(is, "UTF-8");
YamlReader yamlReader = new YamlReader(reader);
yamlReader.getConfig().setPrivateFields(true);
CountryInfo result = yamlReader.read(CountryInfo.class);
result.countryCode = countryCodeIso3166;
return result;
} finally {
if (is != null)
try {
is.close();
} catch (IOException e) {
}
}
}
use of com.esotericsoftware.yamlbeans.YamlReader in project audit4j-core by audit4j.
the class YAMLConfigProvider method readConfig.
/**
* {@inheritDoc}
*
* @see org.audit4j.core.ConfigProvider#readConfig(java.lang.String)
*/
@SuppressWarnings("unchecked")
@Override
public T readConfig(String filePath) throws ConfigurationException {
try {
YamlReader reader = new YamlReader(new FileReader(filePath));
reader.getConfig().setClassTag(clazz.getSimpleName(), clazz);
return (T) reader.read();
} catch (FileNotFoundException e) {
throw new ConfigurationException("Configuration Exception", "CONF_001", e);
} catch (YamlException e) {
throw new ConfigurationException("Configuration Exception", "CONF_002", e);
}
}
use of com.esotericsoftware.yamlbeans.YamlReader in project ecs-dashboard by carone1.
the class KibanaEmailer method loadConfig.
/*
* Utility method to load and parse emailer's configuration data
*/
@SuppressWarnings("unchecked")
private static void loadConfig() {
try {
FileReader fr;
fr = new FileReader(kibanaConfigFile);
logger.info("Loading configuration from config file: " + kibanaConfigFile);
YamlReader reader = new YamlReader(fr);
Object object = reader.read();
if (object == null) {
logger.info("Can't load config data from: " + kibanaConfigFile + " exiting...");
System.out.println("Can't load config data from: " + kibanaConfigFile + " exiting...");
System.exit(0);
}
Map<?, ?> map = (Map<?, ?>) object;
if (map == null) {
logger.info("Can't load config data from: " + kibanaConfigFile + " exiting...");
System.out.println("Can't load config data from: " + kibanaConfigFile + " exiting...");
System.exit(0);
}
// chromedriver
Object driverPathObj = map.get(CHROME_DRIVER_CONFIG);
if (driverPathObj != null && driverPathObj instanceof String) {
chromeDriverPath = (String) driverPathObj;
} else {
logger.info("Can't find: " + CHROME_DRIVER_CONFIG + " in " + kibanaConfigFile + " exiting...");
System.out.println("Can't find: " + CHROME_DRIVER_CONFIG + " in " + kibanaConfigFile + " exiting...");
System.exit(0);
}
// chromebrowser
Object browserPathObj = map.get(CHROME_BROWSER_CONFIG);
if (browserPathObj != null && browserPathObj instanceof String) {
chromeBrowserPath = (String) browserPathObj;
} else {
logger.info("Can't find: " + CHROME_BROWSER_CONFIG + " in " + kibanaConfigFile + " exiting...");
System.out.println("Can't find: " + CHROME_BROWSER_CONFIG + " in " + kibanaConfigFile + " exiting...");
System.exit(0);
}
Object captureDelayObj = map.get(SCREEN_CAPTURE_DELAY);
if (captureDelayObj != null && captureDelayObj instanceof String) {
screenCaptureDelay = Integer.valueOf((String) captureDelayObj);
} else {
logger.info("Can't find: " + SCREEN_CAPTURE_DELAY + " in " + kibanaConfigFile + " exiting...");
System.out.println("Can't find: " + SCREEN_CAPTURE_DELAY + " in " + kibanaConfigFile + " exiting...");
System.exit(0);
}
// Kibana Urls
Object urls = map.get(KIBANA_URLS_CONFIG);
if (urls != null && urls instanceof ArrayList<?>) {
kibanaUrls = (ArrayList<Map<String, String>>) urls;
} else {
logger.info("Can't find: " + KIBANA_URLS_CONFIG + " in " + kibanaConfigFile + " exiting...");
System.out.println("Can't find: " + KIBANA_URLS_CONFIG + " in " + kibanaConfigFile + " exiting...");
System.exit(0);
}
// destination path to save screen captures
Object destinationObj = map.get(DESTINATION_PATH_CONFIG);
if (destinationObj != null && destinationObj instanceof String) {
destinationPath = (String) destinationObj;
} else {
logger.info("Can't find: " + DESTINATION_PATH_CONFIG + " in " + kibanaConfigFile + " exiting...");
System.out.println("Can't find: " + DESTINATION_PATH_CONFIG + " in " + kibanaConfigFile + " exiting...");
System.exit(0);
}
// == smtp config ==
// smtp.host
Object smtpHostObj = map.get(SMTP_HOST_CONFIG);
if (smtpHostObj != null && smtpHostObj instanceof String) {
smtpHost = (String) smtpHostObj;
} else {
logger.info("Can't find: " + SMTP_HOST_CONFIG + " in " + kibanaConfigFile + " exiting...");
System.out.println("Can't find: " + SMTP_HOST_CONFIG + " in " + kibanaConfigFile + " exiting...");
System.exit(0);
}
// smtp.port
Object smtpPortObj = map.get(SMTP_PORT_CONFIG);
if (smtpPortObj != null && smtpPortObj instanceof String) {
smtpPort = (String) smtpHostObj;
} else {
logger.info("Can't find: " + SMTP_PORT_CONFIG + " in " + kibanaConfigFile + " exiting...");
System.out.println("Can't find: " + SMTP_PORT_CONFIG + " in " + kibanaConfigFile + " exiting...");
System.exit(0);
}
// smtp.username
Object smtpUsernameObj = map.get(SMTP_USERNAME_CONFIG);
if (smtpUsernameObj != null && smtpUsernameObj instanceof String) {
smtpUsername = (String) smtpUsernameObj;
} else {
logger.info("Can't find: " + SMTP_USERNAME_CONFIG + " in " + kibanaConfigFile + " exiting...");
System.out.println("Can't find: " + SMTP_USERNAME_CONFIG + " in " + kibanaConfigFile + " exiting...");
System.exit(0);
}
// smtp.password
Object smtpPasswordObj = map.get(SMTP_PASSWORD_CONFIG);
if (smtpPasswordObj != null && smtpPasswordObj instanceof String) {
smtpPassword = (String) smtpPasswordObj;
} else {
logger.info("Can't find: " + SMTP_PASSWORD_CONFIG + " in " + kibanaConfigFile + " exiting...");
System.out.println("Can't find: " + SMTP_PASSWORD_CONFIG + " in " + kibanaConfigFile + " exiting...");
System.exit(0);
}
// smtp.security "tls|ssl"
Object smtpSecurityObj = map.get(SMTP_SECURITY_CONFIG);
if (smtpSecurityObj != null && smtpSecurityObj instanceof String) {
smtpSecurity = (String) smtpSecurityObj;
} else {
logger.info("Can't find: " + SMTP_SECURITY_CONFIG + " in " + kibanaConfigFile + " exiting...");
System.out.println("Can't find: " + SMTP_SECURITY_CONFIG + " in " + kibanaConfigFile + " exiting...");
System.exit(0);
}
// source.host
Object sourceHostObj = map.get(SOURCE_HOST_CONFIG);
if (sourceHostObj != null && sourceHostObj instanceof String) {
sourceHost = (String) sourceHostObj;
} else {
logger.info("Can't find: " + SOURCE_HOST_CONFIG + " in " + kibanaConfigFile + " exiting...");
System.out.println("Can't find: " + SOURCE_HOST_CONFIG + " in " + kibanaConfigFile + " exiting...");
System.exit(0);
}
// e-mail addresses configuration
// source.mail
Object sourceAddressObj = map.get(SOURCE_ADDRESS_CONFIG);
if (sourceAddressObj != null && sourceAddressObj instanceof String) {
sourceAddress = (String) sourceAddressObj;
} else {
logger.info("Can't find: " + SOURCE_ADDRESS_CONFIG + " in " + kibanaConfigFile + " exiting...");
System.out.println("Can't find: " + SOURCE_ADDRESS_CONFIG + " in " + kibanaConfigFile + " exiting...");
System.exit(0);
}
// destination.addresses
Object destinations = map.get(DESTINATION_ADDRESS_CONFIG);
if (destinations != null && destinations instanceof ArrayList<?>) {
destinationAddressList = (ArrayList<String>) destinations;
} else {
logger.info("Can't find: " + DESTINATION_ADDRESS_CONFIG + " in " + kibanaConfigFile + " exiting...");
System.out.println("Can't find: " + DESTINATION_ADDRESS_CONFIG + " in " + kibanaConfigFile + " exiting...");
System.exit(0);
}
// e-mail content
// mail.title
Object mailTitleObj = map.get(MAIL_TITLE_CONFIG);
if (mailTitleObj != null && mailTitleObj instanceof String) {
mailTitle = (String) mailTitleObj;
} else {
logger.info("Can't find: " + MAIL_TITLE_CONFIG + " in " + kibanaConfigFile + " exiting...");
System.out.println("Can't find: " + MAIL_TITLE_CONFIG + " in " + kibanaConfigFile + " exiting...");
System.exit(0);
}
// mail.body
Object mailBodyObj = map.get(MAIL_BODY_CONFIG);
if (mailBodyObj != null && mailBodyObj instanceof String) {
mailBody = (String) mailBodyObj;
} else {
logger.info("Can't find: " + MAIL_BODY_CONFIG + " in " + kibanaConfigFile + " exiting...");
System.out.println("Can't find: " + MAIL_BODY_CONFIG + " in " + kibanaConfigFile + " exiting...");
System.exit(0);
}
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
} catch (YamlException e) {
throw new RuntimeException(e);
}
logger.info("Loaded config details: " + SMTP_HOST_CONFIG + ": `" + smtpHost + "`, " + SMTP_PORT_CONFIG + ": `" + smtpPort.toString() + "`, " + SMTP_USERNAME_CONFIG + ": `" + smtpUsername + "`, " + SOURCE_HOST_CONFIG + ": `" + sourceHost + "`, " + SOURCE_ADDRESS_CONFIG + ": `" + sourceAddress + "`, " + DESTINATION_ADDRESS_CONFIG + ": `" + destinationAddressList.toString() + "`, " + MAIL_TITLE_CONFIG + ": `" + mailTitle + "`, " + MAIL_BODY_CONFIG + ": `" + mailBody);
logger.info("Loaded config details: " + KIBANA_URLS_CONFIG + ": " + kibanaUrls.toString());
}
Aggregations