當前位置: 首頁>>代碼示例>>Java>>正文


Java Yaml類代碼示例

本文整理匯總了Java中org.yaml.snakeyaml.Yaml的典型用法代碼示例。如果您正苦於以下問題:Java Yaml類的具體用法?Java Yaml怎麽用?Java Yaml使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Yaml類屬於org.yaml.snakeyaml包,在下文中一共展示了Yaml類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: loadInner

import org.yaml.snakeyaml.Yaml; //導入依賴的package包/類
@Override
protected synchronized Map<String, Mapping> loadInner(Yaml yaml, InputStream is) throws ConfigurationException {
    Map<String, Map<String, Object>> flesh = yaml.loadAs(is, Map.class);
    Map<String, Mapping> config = new HashMap<>();

    for (Map.Entry<String, Map<String, Object>> entry : flesh.entrySet()) {
        Map<String, Object> rawMapping = entry.getValue();

        String contextName = entry.getKey();
        String mvoClassStr = (String) rawMapping.get("mvo");
        String dtoClassStr = (String) rawMapping.get("dto");
        Map<String, Map<String, String>> attrs = (Map<String, Map<String, String>>) rawMapping.get("attrs");
        try {
            Mapping mapping = new Mapping(contextName, mvoClassStr, dtoClassStr, attrs);
            config.put(contextName, mapping);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    return Collections.unmodifiableMap(config);
}
 
開發者ID:openNaEF,項目名稱:openNaEF,代碼行數:22,代碼來源:AttrNameMapping.java

示例2: writeConfigToYaml

import org.yaml.snakeyaml.Yaml; //導入依賴的package包/類
public static void writeConfigToYaml(ConfigSetting configSetting) {
    try {
        Yaml yaml = new Yaml();
        String output = yaml.dump(configSetting);
        byte[] sourceByte = output.getBytes();
        File file = new File(Constants.CONFIG_FILEPATH);
        if (!file.exists()) {
            file.createNewFile();
        }
        FileOutputStream fileOutputStream = new FileOutputStream(file);
        fileOutputStream.write(sourceByte);
        fileOutputStream.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
開發者ID:neal1991,項目名稱:everywhere,代碼行數:17,代碼來源:ConfigController.java

示例3: loadServerFromConfigFile

import org.yaml.snakeyaml.Yaml; //導入依賴的package包/類
/**
 * 加載配置文件
 */
private void loadServerFromConfigFile() {
    InputStream inputStream = parseYamlFile(CONFIG_FILE_NAME, true);
    Yaml yaml = new Yaml();
    YamlServerConfig config = yaml.loadAs(inputStream, YamlServerConfig.class);

    List<YamlServerList> servers = config.servers;
    for (YamlServerList server : servers) {
        for (ServerInstance instance : server.getInstances()) {
            instance.setServiceName(server.getServiceName());
            instance.ready();
        }
        instanceMap.put(server.getServiceName(), server.getInstances());
    }
    log.info("成功加載server的配置文件:{},Server:{}", CONFIG_FILE_NAME, instanceMap);
}
 
開發者ID:darren-fu,項目名稱:RestyPass,代碼行數:19,代碼來源:ConfigurableServerContext.java

示例4: initUserSettingsProducer

import org.yaml.snakeyaml.Yaml; //導入依賴的package包/類
@PostConstruct
private void initUserSettingsProducer() {
  try {
    File coreYml = new File(BiliomiContainer.getParameters().getConfigurationDir(), "core.yml");
    Yaml yamlInstance = new Yaml(new Constructor(YamlCoreSettings.class));
    yamlCoreSettings = yamlInstance.loadAs(new FileInputStream(coreYml), YamlCoreSettings.class);

    String updateMode = yamlCoreSettings.getBiliomi().getCore().getUpdateMode();
    // Somehow Yaml thinks "off" means "false"
    if (StringUtils.isEmpty(updateMode)) {
      this.updateMode = UpdateModeType.OFF;
    } else {
      this.updateMode = EnumUtils.toEnum(updateMode, UpdateModeType.class);
    }
  } catch (FileNotFoundException e) {
    this.yamlCoreSettings = new YamlCoreSettings();
    ObjectGraphs.initializeObjectGraph(this.yamlCoreSettings);
    this.updateMode = UpdateModeType.INSTALL;
    this.yamlCoreSettings.getBiliomi().getCore().setUpdateMode(this.updateMode.toString());
  }
}
 
開發者ID:Juraji,項目名稱:Biliomi,代碼行數:22,代碼來源:UserSettingsProducer.java

示例5: testConfigShouldBuildWithoutQueryRef

import org.yaml.snakeyaml.Yaml; //導入依賴的package包/類
@Test
public void testConfigShouldBuildWithoutQueryRef() {
  JdbcConfig config = new JdbcConfig((Map<String, Object>) new Yaml().load("---\n" +
      "jobs:\n" +
      "- name: \"global\"\n" +
      "  connections:\n" +
      "  - url: jdbc\n" +
      "    username: sys\n" +
      "    password: sys\n" +
      "  queries:\n" +
      "  - name: jdbc\n" +
      "    values:\n" +
      "    - v1\n" +
      "    query: abc\n" +
      ""));
  assertNotNull(config);
}
 
開發者ID:sysco-middleware,項目名稱:prometheus-jdbc-exporter,代碼行數:18,代碼來源:JdbcConfigTest.java

示例6: testMustasche

import org.yaml.snakeyaml.Yaml; //導入依賴的package包/類
@Test
@SuppressWarnings("unchecked")
public void testMustasche() throws IOException {
	Yaml yaml = new Yaml();
	Map model = (Map) yaml.load(valuesResource.getInputStream());
	String templateAsString = StreamUtils.copyToString(nestedMapResource.getInputStream(),
			Charset.defaultCharset());
	Template mustacheTemplate = Mustache.compiler().compile(templateAsString);
	String resolvedYml = mustacheTemplate.execute(model);
	Map map = (Map) yaml.load(resolvedYml);

	logger.info("Resolved yml = " + resolvedYml);
	assertThat(map).containsKeys("apiVersion", "deployment");
	Map deploymentMap = (Map) map.get("deployment");
	assertThat(deploymentMap).contains(entry("name", "time"))
			.contains(entry("count", 10));
	Map applicationProperties = (Map) deploymentMap.get("applicationProperties");
	assertThat(applicationProperties).contains(entry("log.level", "DEBUG"), entry("server.port", 8089));
	Map deploymentProperties = (Map) deploymentMap.get("deploymentProperties");
	assertThat(deploymentProperties).contains(entry("app.time.producer.partitionKeyExpression", "payload"),
			entry("app.log.spring.cloud.stream.bindings.input.consumer.maxAttempts", 5));
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-skipper,代碼行數:23,代碼來源:PackageTemplateTests.java

示例7: get

import org.yaml.snakeyaml.Yaml; //導入依賴的package包/類
public static MediaToolConfig get(Path config)
{
    try {
        Yaml yaml = new Yaml();
        try (InputStream in = Files.newInputStream(config))
        {
            MediaToolConfig mediaConfig = yaml.loadAs(in, MediaToolConfig.class);
            if (logger.isInfoEnabled())
                logger.info("{}", mediaConfig.toString());
            return mediaConfig;
        }
    } catch (IOException oie) {
        logger.error("{}", oie.getMessage(), oie);
    }
    return null;
}
 
開發者ID:KKDad,項目名稱:MediaTool,代碼行數:17,代碼來源:YamlConfigLoader.java

示例8: convert

import org.yaml.snakeyaml.Yaml; //導入依賴的package包/類
private YamlConversionResult convert(Map<String, Collection<String>> properties) {
	if (properties.isEmpty()) {
		return YamlConversionResult.EMPTY;
	}

	YamlBuilder root = new YamlBuilder(mode, keyspaceList, status, YamlPath.EMPTY);
	for (Entry<String, Collection<String>> e : properties.entrySet()) {
		for (String v : e.getValue()) {
			root.addProperty(YamlPath.fromProperty(e.getKey()), v);
		}
	}

	Object object = root.build();

	DumperOptions options = new DumperOptions();
	options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
	options.setPrettyFlow(true);

	Yaml yaml = new Yaml(options);
	String output = yaml.dump(object);
	return new YamlConversionResult(status, output);
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-skipper,代碼行數:23,代碼來源:DefaultYamlConverter.java

示例9: testConfigShouldFailIfJobQueryRefNonExistingQuery

import org.yaml.snakeyaml.Yaml; //導入依賴的package包/類
@Test(expected = IllegalArgumentException.class)
public void testConfigShouldFailIfJobQueryRefNonExistingQuery() {
  new JdbcConfig((Map<String, Object>) new Yaml().load("---\n" +
      "jobs:\n" +
      "- name: \"global\"\n" +
      "  connections:\n" +
      "  - url: jdbc\n" +
      "    username: sys\n" +
      "    password: sys\n" +
      "  queries:\n" +
      "  - name: jdbc\n" +
      "    values:\n" +
      "    - v1\n" +
      "    query_ref: abc\n" +
      ""));
}
 
開發者ID:sysco-middleware,項目名稱:prometheus-jdbc-exporter,代碼行數:17,代碼來源:JdbcConfigTest.java

示例10: 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

示例11: main

import org.yaml.snakeyaml.Yaml; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
    if (args.length < 1) {
        System.out.println("Usage: <file.yml> [iffnit]");
        return;
    }

    Yaml yaml = new Yaml();
    try (InputStream in = Files.newInputStream(Paths.get(args[0]))) {
        Configuration config = yaml.loadAs(in, Configuration.class);
        System.out.println(config.toString());
    }

    if (args.length > 1 && args[1].equals("init")) {
        ReplicaInit replicaInit = new ReplicaInit();
        replicaInit.start();
    } else if (args.length > 1 && !args[1].equals("init")) {
        System.out.println("Usage: <file.yml> [init]");
    } else {
        ReplicaEvent replicaEvent = new ReplicaEvent();
        replicaEvent.start();
    }
}
 
開發者ID:mapcentia,項目名稱:DAWAreplicator,代碼行數:23,代碼來源:Main.java

示例12: 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

示例13: testMissingGithubCoordinate

import org.yaml.snakeyaml.Yaml; //導入依賴的package包/類
@Test
public void testMissingGithubCoordinate() throws Exception {
  CDepYml config = new CDepYml();
  System.out.printf(new Yaml().dump(config));
  File yaml = new File(".test-files/runMathfu/cdep.yml");
  yaml.getParentFile().mkdirs();
  Files.write("builders: [cmake, cmakeExamples]\ndependencies:\n- compile: com.github.jomof:mathfoo:1.0.2-rev7\n",
      yaml, StandardCharsets.UTF_8);
  try {
    String result = main("-wf", yaml.getParent());
    System.out.printf(result);
    fail("Expected an exception");
  } catch (RuntimeException e) {
    assertThat(e).hasMessage("Could not resolve 'com.github.jomof:mathfoo:1.0.2-rev7'. It doesn't exist.");
  }
}
 
開發者ID:jomof,項目名稱:cdep,代碼行數:17,代碼來源:TestCDep.java

示例14: unfindableLocalFile

import org.yaml.snakeyaml.Yaml; //導入依賴的package包/類
@Test
public void unfindableLocalFile() throws Exception {
  CDepYml config = new CDepYml();
  System.out.printf(new Yaml().dump(config));
  File yaml = new File(".test-files/unfindableLocalFile/cdep.yml");
  yaml.getParentFile().mkdirs();
  Files.write("builders: [cmake, cmakeExamples]\ndependencies:\n- compile: ../not-a-file/cdep-manifest.yml\n",
      yaml, StandardCharsets.UTF_8);

  try {
    main("-wf", yaml.getParent());
    fail("Expected failure");
  } catch (RuntimeException e) {
    assertThat(e).hasMessage("Could not resolve '../not-a-file/cdep-manifest.yml'. It doesn't exist.");
  }
}
 
開發者ID:jomof,項目名稱:cdep,代碼行數:17,代碼來源:TestCDep.java

示例15: sqlite

import org.yaml.snakeyaml.Yaml; //導入依賴的package包/類
@Test
public void sqlite() throws Exception {
  CDepYml config = new CDepYml();
  System.out.printf(new Yaml().dump(config));
  File yaml = new File(".test-files/firebase/cdep.yml");
  yaml.getParentFile().mkdirs();
  Files.write("builders: [cmake, cmakeExamples]\n"
          + "dependencies:\n"
          + "- compile: com.github.jomof:sqlite:3.16.2-rev45\n",
      yaml, StandardCharsets.UTF_8);
  String result1 = main("show", "manifest", "-wf", yaml.getParent());
  yaml.delete();
  Files.write(result1, yaml, StandardCharsets.UTF_8);
  System.out.print(result1);
  String result = main("-wf", yaml.getParent());
  System.out.printf(result);
}
 
開發者ID:jomof,項目名稱:cdep,代碼行數:18,代碼來源:TestCDep.java


注:本文中的org.yaml.snakeyaml.Yaml類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。