本文整理汇总了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);
}
示例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();
}
}
示例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);
}
示例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());
}
}
示例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);
}
示例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));
}
示例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;
}
示例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);
}
示例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" +
""));
}
示例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));
}
示例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();
}
}
示例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;
}
示例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.");
}
}
示例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.");
}
}
示例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);
}