Search in sources :

Example 1 with MemberXmlConfigRootTagRecognizer

use of com.hazelcast.internal.config.MemberXmlConfigRootTagRecognizer in project hazelcast by hazelcast.

the class Config method loadFromStream.

/**
 * Creates a Config from the provided stream (XML or YAML content).
 *
 * @param source the XML or YAML stream
 * @param properties properties to use for variable resolution
 * @return Config created from the stream
 */
public static Config loadFromStream(InputStream source, Properties properties) {
    isNotNull(source, "(InputStream) source");
    try {
        ConfigStream cfgStream = new ConfigStream(source);
        if (new MemberXmlConfigRootTagRecognizer().isRecognized(cfgStream)) {
            cfgStream.reset();
            InputStream stream = new SequenceInputStream(cfgStream, source);
            return applyEnvAndSystemVariableOverrides(new XmlConfigBuilder(stream).setProperties(properties).build());
        }
        cfgStream.reset();
        if (new MemberYamlConfigRootTagRecognizer().isRecognized(cfgStream)) {
            cfgStream.reset();
            InputStream stream = new SequenceInputStream(cfgStream, source);
            return applyEnvAndSystemVariableOverrides(new YamlConfigBuilder(stream).setProperties(properties).build());
        }
    } catch (Exception e) {
        throw ExceptionUtil.rethrow(e);
    }
    throw new IllegalArgumentException("interpretation error: the resource is neither valid XML nor valid YAML");
}
Also used : MemberYamlConfigRootTagRecognizer(com.hazelcast.internal.config.MemberYamlConfigRootTagRecognizer) SequenceInputStream(java.io.SequenceInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) SequenceInputStream(java.io.SequenceInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) MemberXmlConfigRootTagRecognizer(com.hazelcast.internal.config.MemberXmlConfigRootTagRecognizer) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Aggregations

MemberXmlConfigRootTagRecognizer (com.hazelcast.internal.config.MemberXmlConfigRootTagRecognizer)1 MemberYamlConfigRootTagRecognizer (com.hazelcast.internal.config.MemberYamlConfigRootTagRecognizer)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 SequenceInputStream (java.io.SequenceInputStream)1