[ML] Load resource and split into keys manually (elastic/x-pack-elasticsearch#786)

Manually loads the resources, splits the lines and fills the map instead of using the ResourceBundle stuff. 

relates elastic/x-pack-elasticsearch#750 

Original commit: elastic/x-pack-elasticsearch@25ff4d5d19
This commit is contained in:
Zachary Tong 2017-03-22 15:24:47 -04:00 committed by GitHub
parent 5c4933f5ea
commit cc7a1a821f
1 changed files with 15 additions and 9 deletions

View File

@ -5,12 +5,13 @@
*/ */
package org.elasticsearch.xpack.ml.utils; package org.elasticsearch.xpack.ml.utils;
import org.elasticsearch.common.io.Streams;
import java.io.InputStream;
import java.util.Collections; import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap; import java.util.HashMap;
import java.util.Locale; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.ResourceBundle;
public final class DomainSplitFunction { public final class DomainSplitFunction {
@ -21,13 +22,18 @@ public final class DomainSplitFunction {
static { static {
Map<String, Object> paramsMap = new HashMap<>(); Map<String, Object> paramsMap = new HashMap<>();
ResourceBundle resource = ResourceBundle.getBundle("org/elasticsearch/xpack/ml/transforms/exact", Locale.ROOT);
Enumeration<String> keys = resource.getKeys();
Map<String, String> exact = new HashMap<>(2048); Map<String, String> exact = new HashMap<>(2048);
while (keys.hasMoreElements()) { try {
String key = keys.nextElement(); InputStream resource =
String value = resource.getString(key); DomainSplitFunction.class.getClassLoader().getResourceAsStream("org/elasticsearch/xpack/ml/transforms/exact.properties");
exact.put(key, value); List<String> lines = Streams.readAllLines(resource);
for (String line : lines) {
String[] split = line.split("=");
exact.put(split[0].trim(), split[1].trim());
}
} catch (Exception e) {
throw new RuntimeException("Could not load DomainSplit resource", e);
} }
exact = Collections.unmodifiableMap(exact); exact = Collections.unmodifiableMap(exact);