当前位置: 首页>>代码示例>>Java>>正文


Java Yaml.load方法代码示例

本文整理汇总了Java中org.yaml.snakeyaml.Yaml.load方法的典型用法代码示例。如果您正苦于以下问题:Java Yaml.load方法的具体用法?Java Yaml.load怎么用?Java Yaml.load使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.yaml.snakeyaml.Yaml的用法示例。


在下文中一共展示了Yaml.load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: assertConfigValues

import org.yaml.snakeyaml.Yaml; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
protected void assertConfigValues(Package pkg) {
	// Note same config values for both time and log
	ConfigValues configValues = pkg.getConfigValues();
	Yaml yaml = new Yaml();
	Map<String, Object> logConfigValueMap = (Map<String, Object>) yaml.load(configValues.getRaw());
	assertThat(logConfigValueMap).containsKeys("version", "spec");
	if (pkg.getMetadata().getName().equals("log")) {
		assertThat(logConfigValueMap.get("version")).isEqualTo("1.1.0.RELEASE");
	}
	if (pkg.getMetadata().getName().equals("time")) {
		assertThat(logConfigValueMap.get("version")).isEqualTo("1.2.0.RELEASE");
	}
	Map<String, Object> spec = (Map<String, Object>) logConfigValueMap.get("spec");
	assertThat(spec).hasSize(2);
	Map<String, String> applicationProperties = (Map<String, String>) spec.get("applicationProperties");
	assertThat(applicationProperties).hasSize(1);
	assertThat(applicationProperties).contains(entry("log.level", "DEBUG"));
	Map<String, String> deploymentProperties = (Map<String, String>) spec.get("deploymentProperties");
	assertThat(deploymentProperties).hasSize(1);
	assertThat(deploymentProperties).contains(entry("memory", "1024m"));

}
 
开发者ID:spring-cloud,项目名称:spring-cloud-skipper,代码行数:24,代码来源:PackageServiceTests.java

示例2: load

import org.yaml.snakeyaml.Yaml; //导入方法依赖的package包/类
public void load() throws IOException {
    Yaml yaml = new Yaml();

    InputStream file = new FileInputStream(fileName);
    Object settingsTmp = yaml.load(file);
    if (!(settingsTmp instanceof Map))
        throw new IOException("File not formatted correctly");

    Map<String, Object> settings = (Map<String, Object>) settingsTmp;

    try {
        file.close();
    } catch (IOException e) {
        // Should never happen
        logger.warn(e);
    }

    if (!this.isValid(settings))
        throw new IOException("File not formatted correctly");

    this.bots = (Map<String, Object>) settings.get(Config.BOTS_KEY);
    this.channels = (Map<String, Object>) settings.get(Config.CHANNELS_KEY);
    this.bridges = (ArrayList) settings.get(Config.BRIDGES_KEY);
    this.webserver = (Map<String, String>) settings.get(Config.WEBSERVER_KEY);
}
 
开发者ID:KDE,项目名称:brooklyn,代码行数:26,代码来源:Config.java

示例3: assertTickTockPackage

import org.yaml.snakeyaml.Yaml; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private void assertTickTockPackage(Package pkg) {
	PackageMetadata metadata = pkg.getMetadata();
	assertThat(metadata.getApiVersion()).isEqualTo("skipper.spring.io/v1");
	assertThat(metadata.getKind()).isEqualTo("SkipperPackageMetadata");
	assertThat(metadata.getName()).isEqualTo("ticktock");
	assertThat(metadata.getVersion()).isEqualTo("1.0.0");
	assertThat(metadata.getPackageSourceUrl()).isEqualTo("https://example.com/dataflow/ticktock");
	assertThat(metadata.getPackageHomeUrl()).isEqualTo("http://example.com/dataflow/ticktock");
	Set<String> tagSet = convertToSet(metadata.getTags());
	assertThat(tagSet).hasSize(3).contains("stream", "time", "log");
	assertThat(metadata.getMaintainer()).isEqualTo("https://github.com/markpollack");
	assertThat(metadata.getDescription()).isEqualTo("The ticktock stream sends a time stamp and logs the value.");
	String rawYamlString = pkg.getConfigValues().getRaw();
	Yaml yaml = new Yaml();
	Map<String, String> valuesAsMap = (Map<String, String>) yaml.load(rawYamlString);
	assertThat(valuesAsMap).hasSize(2).containsEntry("foo", "bar").containsEntry("biz", "baz");

	assertThat(pkg.getDependencies()).hasSize(2);
	assertTimeOrLogPackage(pkg.getDependencies().get(0));
	assertTimeOrLogPackage(pkg.getDependencies().get(1));

}
 
开发者ID:spring-cloud,项目名称:spring-cloud-skipper,代码行数:24,代码来源:PackageReaderTests.java

示例4: convertStringToManifest

import org.yaml.snakeyaml.Yaml; //导入方法依赖的package包/类
@NotNull
public static io.cdep.cdep.yml.cdepmanifest.CDepManifestYml convertStringToManifest(@NotNull String content) {
  Yaml yaml = new Yaml(new Constructor(io.cdep.cdep.yml.cdepmanifest.v3.CDepManifestYml.class));
  io.cdep.cdep.yml.cdepmanifest.CDepManifestYml manifest;
  try {
    CDepManifestYml prior = (CDepManifestYml) yaml.load(
        new ByteArrayInputStream(content.getBytes(StandardCharsets
            .UTF_8)));
    prior.sourceVersion = CDepManifestYmlVersion.v3;
    manifest = convert(prior);
    require(manifest.sourceVersion == CDepManifestYmlVersion.v3);
  } catch (YAMLException e) {
    manifest = convert(V2Reader.convertStringToManifest(content));
  }
  return manifest;
}
 
开发者ID:jomof,项目名称:cdep,代码行数:17,代码来源:V3Reader.java

示例5: importDefaultConfigurations

import org.yaml.snakeyaml.Yaml; //导入方法依赖的package包/类
private void importDefaultConfigurations() throws IOException {
  Resource resource = new ClassPathResource("maps/defaults.yaml");
  Yaml yaml = new Yaml();
  Map<String, Object> mapYaml = (Map<String, Object>) yaml.load(resource.getInputStream());

  setConfigurations((Map<String, Object>) mapYaml.get("simulation"));
}
 
开发者ID:sinaa,项目名称:train-simulator,代码行数:8,代码来源:MapBuilder.java

示例6: load

import org.yaml.snakeyaml.Yaml; //导入方法依赖的package包/类
/**
 * コンフィグファイルを読み込む
 * <p>
 * reload == true の場合はコンフィグファイルをリロードする
 *
 * @param reload リロード
 */
@SuppressWarnings("unchecked")
public void load(boolean reload) throws IOException {
    if (_conf != null && !reload) return;

    Path path = Paths.get(Notifier.BASE_DIR, CONFIG_DIR, CONFIG_FILE);
    Logs.common.debug("config reload: {}", path.toAbsolutePath());

    try (InputStream is = Files.newInputStream(path)) {
        Yaml yaml = new Yaml();
        _conf = (Map<String, Object>) yaml.load(is);
    } catch (IOException ioe) {
        Logs.common.error("config load failed", ioe);
        throw new IOException("設定ファイルの読み込みに失敗しました. file: " + path.toAbsolutePath().toString(), ioe);
    }
}
 
开发者ID:openNaEF,项目名称:openNaEF,代码行数:23,代码来源:NotifierConfig.java

示例7: loadYaml

import org.yaml.snakeyaml.Yaml; //导入方法依赖的package包/类
private Object loadYaml(File file) throws FileNotFoundException {
    FileReader reader = new FileReader(file);
    try {
        Constructor constructor = new Constructor();
        PropertyUtils putils = new PropertyUtils();
        putils.setSkipMissingProperties(true);
        constructor.setPropertyUtils(putils);
        Yaml yaml = new Yaml(constructor);
        return yaml.load(reader);
    } catch (Throwable t) {
        throw new RuntimeException("Error loading yaml from: " + file.getAbsolutePath() + "\n" + t.getMessage(), t);
    } finally {
        try {
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:20,代码来源:OMapContainer.java

示例8: apply

import org.yaml.snakeyaml.Yaml; //导入方法依赖的package包/类
@Override
@SneakyThrows
public DtoDocs apply(final File file) {
  try (final InputStream in = new FileInputStream(file)) {
    final Yaml yaml = new Yaml(new Constructor(DtoDocs.class));
    return (DtoDocs) yaml.load(in);
  }

}
 
开发者ID:camunda,项目名称:camunda-bpm-swagger,代码行数:10,代码来源:DtoDocsYaml.java

示例9: mergeOverrideMap

import org.yaml.snakeyaml.Yaml; //导入方法依赖的package包/类
/**
 * Merge top level configuration values from the Package and the configuration values
 * passed in at runtime.
 * <p>
 * @param pkg The package being configured
 * @param overrideMap The runtime override values
 * @return A merged map of package configuration values and runtime override values.
 */
public static Map<String, Object> mergeOverrideMap(Package pkg, Map<String, Object> overrideMap) {
	// if the package does not have any values, return just the override values.
	if (pkg.getConfigValues() == null || (pkg.getConfigValues() != null &&
			!StringUtils.hasText(pkg.getConfigValues().getRaw()))) {
		return overrideMap;
	}
	// load the package values
	Yaml yaml = new Yaml();
	Object object = yaml.load(pkg.getConfigValues().getRaw());
	if (object == null) {
		// Config Values could have been file with comments only, no data.
		return overrideMap;
	}
	Map<String, Object> packageValueMap;
	if (object instanceof Map) {
		packageValueMap = (Map<String, Object>) object;
	}
	else {
		throw new SkipperException("Config Values that are not a map are not yet supported.");
	}

	// exclude dependency values from being merged into the current packages' values
	if (packageValueMap != null) {
		for (Package dependency : pkg.getDependencies()) {
			if (packageValueMap.containsKey(dependency.getMetadata().getName())) {
				packageValueMap.remove(dependency.getMetadata().getName());
			}
		}
	}
	else {
		packageValueMap = new TreeMap<>();
	}

	merge(packageValueMap, overrideMap);

	return packageValueMap;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-skipper,代码行数:46,代码来源:ConfigValueUtils.java

示例10: convertConfigValuesToMap

import org.yaml.snakeyaml.Yaml; //导入方法依赖的package包/类
private static Map<String, Object> convertConfigValuesToMap(Package pkg) {
	Yaml yaml = new Yaml();
	Map<String, Object> currentPackageValueMap = new TreeMap<>();
	if (pkg.getConfigValues() != null && StringUtils.hasText(pkg.getConfigValues().getRaw())) {
		currentPackageValueMap = (Map<String, Object>) yaml.load(pkg.getConfigValues().getRaw());
	}
	if (currentPackageValueMap == null) {
		currentPackageValueMap = new TreeMap<>();
	}
	return currentPackageValueMap;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-skipper,代码行数:12,代码来源:ConfigValueUtils.java

示例11: parse

import org.yaml.snakeyaml.Yaml; //导入方法依赖的package包/类
static public Config parse(Reader rdr) {
	Yaml yaml = new Yaml(new Constructor(Config.class));
	Config conf = (Config) yaml.load(rdr);
	if(conf.getOutputFormat() == null) 
		conf.setOutputFormat("csv");
	return conf;
}
 
开发者ID:prydin,项目名称:vrops-export,代码行数:8,代码来源:ConfigLoader.java

示例12: convertStringToCDepSHA256

import org.yaml.snakeyaml.Yaml; //导入方法依赖的package包/类
@NotNull
public static CDepSHA256 convertStringToCDepSHA256(@NotNull String content) {
  Yaml yaml = new Yaml(new Constructor(HashEntry[].class));
  HashEntry[] result = (HashEntry[]) yaml.load(new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)));
  if (result == null) {
    result = new HashEntry[0];
  }
  return new CDepSHA256(result);
}
 
开发者ID:jomof,项目名称:cdep,代码行数:10,代码来源:CDepSHA256Utils.java

示例13: getExistingHcmActionsSequence

import org.yaml.snakeyaml.Yaml; //导入方法依赖的package包/类
private static List<Map<Double, Object>> getExistingHcmActionsSequence(final File sourcePath) throws FileNotFoundException {
    final File extensions = new File(sourcePath, HCM_ACTIONS_NAME);
    if (extensions.exists()) {
        Yaml yaml = new Yaml();
        Map<String, List<Map<Double, Object>>> load = (Map<String, List<Map<Double, Object>>>) yaml.load(new FileInputStream(extensions));
        return load.get("action-lists");
    }
    return Collections.emptyList();
}
 
开发者ID:openweb-nl,项目名称:hippo-groovy-updater,代码行数:10,代码来源:YamlGenerator.java

示例14: createFromFile

import org.yaml.snakeyaml.Yaml; //导入方法依赖的package包/类
/**
 * Creates a DocsProject instance from a file.
 * 
 * @param file The page's content.
 * 
 * @return The DocsProject instance.
 * @throws InvalidProjectDataException If the YAML file is invalid.
 */

private static final DocsProject createFromFile(final File file) throws InvalidProjectDataException {
	try {
		final Yaml yaml = new Yaml();
		@SuppressWarnings("unchecked")
		final HashMap<String, Object> data = (HashMap<String, Object>)yaml.load(new FileInputStream(file));

		return new DocsProject(data, file.getParentFile());
	}
	catch(final Exception ex) {
		throw new InvalidProjectDataException(ex);
	}
}
 
开发者ID:Skyost,项目名称:SkyDocs,代码行数:22,代码来源:DocsProject.java

示例15: loadSettings

import org.yaml.snakeyaml.Yaml; //导入方法依赖的package包/类
/**
 * @author wasiq.bhamla
 * @since 09-Jun-2017 5:00:19 PM
 * @param cls
 */
@SuppressWarnings ("unchecked")
private <T> T loadSettings (final Class <T> cls) {
	final String path = System.getProperty (this.key, this.value);
	try (final InputStream in = getClass ().getResourceAsStream (path)) {
		if (in != null) {
			final Constructor ctor = new Constructor (cls);
			final PropertyUtils propertyUtils = new PropertyUtils () {
				@Override
				public Property getProperty (final Class <? extends Object> obj, final String name) {
					String propertyName = name;
					if (propertyName.indexOf ('_') > -1) {
						propertyName = CaseFormat.LOWER_UNDERSCORE.to (CaseFormat.LOWER_CAMEL, propertyName);
					}
					return super.getProperty (obj, propertyName);
				}
			};
			ctor.setPropertyUtils (propertyUtils);
			final Yaml yaml = new Yaml (ctor);
			return (T) yaml.load (in);
		}
	}
	catch (final Exception e) {
		fail (CoteafsConfigNotLoadedError.class, "Error loading config file.", e);
	}
	final String MSG = "%s not found.";
	fail (CoteafsConfigFileNotFoundError.class, String.format (MSG, path));
	return null;
}
 
开发者ID:WasiqB,项目名称:coteafs-config,代码行数:34,代码来源:ConfigLoader.java


注:本文中的org.yaml.snakeyaml.Yaml.load方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。