當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。