summaryrefslogtreecommitdiff
path: root/core/src/main/java/org/elasticsearch/common/settings/Settings.java
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/main/java/org/elasticsearch/common/settings/Settings.java')
-rw-r--r--core/src/main/java/org/elasticsearch/common/settings/Settings.java22
1 files changed, 20 insertions, 2 deletions
diff --git a/core/src/main/java/org/elasticsearch/common/settings/Settings.java b/core/src/main/java/org/elasticsearch/common/settings/Settings.java
index 883f1e7c82..579be7ce31 100644
--- a/core/src/main/java/org/elasticsearch/common/settings/Settings.java
+++ b/core/src/main/java/org/elasticsearch/common/settings/Settings.java
@@ -37,6 +37,7 @@ import org.elasticsearch.common.unit.SizeValue;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
+import org.elasticsearch.common.xcontent.XContentType;
import java.io.IOException;
import java.io.InputStream;
@@ -960,7 +961,9 @@ public final class Settings implements ToXContent {
/**
* Loads settings from the actual string content that represents them using the
* {@link SettingsLoaderFactory#loaderFromSource(String)}.
+ * @deprecated use {@link #loadFromSource(String, XContentType)} to avoid content type detection
*/
+ @Deprecated
public Builder loadFromSource(String source) {
SettingsLoader settingsLoader = SettingsLoaderFactory.loaderFromSource(source);
try {
@@ -973,8 +976,23 @@ public final class Settings implements ToXContent {
}
/**
+ * Loads settings from the actual string content that represents them using the
+ * {@link SettingsLoaderFactory#loaderFromXContentType(XContentType)} method to obtain a loader
+ */
+ public Builder loadFromSource(String source, XContentType xContentType) {
+ SettingsLoader settingsLoader = SettingsLoaderFactory.loaderFromXContentType(xContentType);
+ try {
+ Map<String, String> loadedSettings = settingsLoader.load(source);
+ put(loadedSettings);
+ } catch (Exception e) {
+ throw new SettingsException("Failed to load settings from [" + source + "]", e);
+ }
+ return this;
+ }
+
+ /**
* Loads settings from a url that represents them using the
- * {@link SettingsLoaderFactory#loaderFromSource(String)}.
+ * {@link SettingsLoaderFactory#loaderFromResource(String)}.
*/
public Builder loadFromPath(Path path) throws IOException {
// NOTE: loadFromStream will close the input stream
@@ -983,7 +1001,7 @@ public final class Settings implements ToXContent {
/**
* Loads settings from a stream that represents them using the
- * {@link SettingsLoaderFactory#loaderFromSource(String)}.
+ * {@link SettingsLoaderFactory#loaderFromResource(String)}.
*/
public Builder loadFromStream(String resourceName, InputStream is) throws IOException {
SettingsLoader settingsLoader = SettingsLoaderFactory.loaderFromResource(resourceName);