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


Java Yaml.dump方法代码示例

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


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

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

示例2: getYamlConfigValues

import org.yaml.snakeyaml.Yaml; //导入方法依赖的package包/类
public static String getYamlConfigValues(File yamlFile, String properties) {
	String configValuesYML = null;
	if (yamlFile != null) {
		Yaml yaml = new Yaml();
		// Validate it is yaml formatted.
		try {
			configValuesYML = yaml.dump(yaml.load(new FileInputStream(yamlFile)));
		}
		catch (FileNotFoundException e) {
			throw new SkipperException("Could not find file " + yamlFile.toString());
		}
	}
	else if (StringUtils.hasText(properties)) {
		configValuesYML = convertToYaml(properties);
	}
	return configValuesYML;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-skipper,代码行数:18,代码来源:YmlUtils.java

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

示例4: testYamlMerge

import org.yaml.snakeyaml.Yaml; //导入方法依赖的package包/类
@Test
public void testYamlMerge() throws IOException {
	DumperOptions dumperOptions = new DumperOptions();
	dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
	dumperOptions.setPrettyFlow(true);
	Yaml yaml = new Yaml(dumperOptions);

	Resource resource = new ClassPathResource("/org/springframework/cloud/skipper/server/service/ticktock-1.0.0");

	Package pkg = this.packageReader.read(resource.getFile());
	ConfigValues configValues = new ConfigValues();
	Map<String, Object> configValuesMap = new TreeMap<>();
	Map<String, Object> logMap = new TreeMap<>();
	logMap.put("appVersion", "1.2.1.RELEASE");
	configValuesMap.put("log", logMap);
	configValuesMap.put("hello", "universe");

	String configYaml = yaml.dump(configValuesMap);
	configValues.setRaw(configYaml);
	Map<String, Object> mergedMap = ConfigValueUtils.mergeConfigValues(pkg, configValues);

	String mergedYaml = yaml.dump(mergedMap);
	String expectedYaml = StreamUtils.copyToString(
			TestResourceUtils.qualifiedResource(getClass(), "merged.yaml").getInputStream(),
			Charset.defaultCharset());
	assertThat(mergedYaml).isEqualTo(expectedYaml);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-skipper,代码行数:28,代码来源:ConfigValueUtilsTests.java

示例5: sanitizeYml

import org.yaml.snakeyaml.Yaml; //导入方法依赖的package包/类
/**
 * Redacts the values stored for keys that contain the following:  password,
 * secret, key, token, *credentials.*.
 * @param yml String containing a yaml.
 * @return redacted yaml String.
 */
public static String sanitizeYml(String yml) {
	String result = "";
	try {
		DumperOptions options = new DumperOptions();
		options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
		options.setPrettyFlow(true);
		Yaml yaml = new Yaml(options);
		Iterator<Object> iter = yaml.loadAll(yml).iterator();
		while (iter.hasNext()) {
			Object o = iter.next();
			if (o instanceof LinkedHashMap) {
				iterateLinkedHashMap((LinkedHashMap<String, Object>) o);
			}
			result += yaml.dump(o);
		}
	}
	catch (Throwable throwable) {
		logger.error("Unable to redact data from Manifest debug entry", throwable);
	}
	if (result == null || result.length() == 0) {
		result = yml;
	}
	return result;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-skipper,代码行数:31,代码来源:ArgumentSanitizer.java

示例6: save

import org.yaml.snakeyaml.Yaml; //导入方法依赖的package包/类
public boolean save(Boolean async) {
    if (this.file == null) throw new IllegalStateException("Failed to save Config. File object is undefined.");
    if (this.correct) {
        String content = "";
        switch (this.type) {
            case Config.PROPERTIES:
                content = this.writeProperties();
                break;
            case Config.JSON:
                content = new GsonBuilder().setPrettyPrinting().create().toJson(this.config);
                break;
            case Config.YAML:
                DumperOptions dumperOptions = new DumperOptions();
                dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
                Yaml yaml = new Yaml(dumperOptions);
                content = yaml.dump(this.config);
                break;
            case Config.ENUM:
                for (Object o : this.config.entrySet()) {
                    Map.Entry entry = (Map.Entry) o;
                    content += String.valueOf(entry.getKey()) + "\r\n";
                }
                break;
        }
        if (async) {
            Server.getInstance().getScheduler().scheduleAsyncTask(new FileWriteTask(this.file, content));

        } else {
            try {
                Utils.writeFile(this.file, content);
            } catch (IOException e) {
                Server.getInstance().getLogger().logException(e);
            }
        }
        return true;
    } else {
        return false;
    }
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:40,代码来源:Config.java

示例7: loadConfigFile

import org.yaml.snakeyaml.Yaml; //导入方法依赖的package包/类
/**
 * Makes sure the requested config file exists in the current format. Will attempt to migrate old formats to new ones
 * old files will be renamed to filename.ext.old to preserve any data
 *
 * @param name relative name of a config file, without the file extension
 * @return a handle on the requested file
 */
private static File loadConfigFile(String name) throws IOException {
    String yamlPath = "./" + name + ".yaml";
    String jsonPath = "./" + name + ".json";
    File yamlFile = new File(yamlPath);
    if (!yamlFile.exists() || yamlFile.isDirectory()) {
        log.warn("Could not find file '" + yamlPath + "', looking for legacy '" + jsonPath + "' to rewrite");
        File json = new File(jsonPath);
        if (!json.exists() || json.isDirectory()) {
            //file is missing
            log.error("No " + name + " file is present. Bot cannot run without it. Check the documentation.");
            throw new FileNotFoundException("Neither '" + yamlPath + "' nor '" + jsonPath + "' present");
        } else {
            //rewrite the json to yaml
            Yaml yaml = new Yaml();
            String fileStr = FileUtils.readFileToString(json, "UTF-8");
            //remove tab character from json file to make it a valid YAML file
            fileStr = fileStr.replaceAll("\t", "");
            @SuppressWarnings("unchecked")
            Map<String, Object> configFile = (Map) yaml.load(fileStr);
            yaml.dump(configFile, new FileWriter(yamlFile));
            Files.move(Paths.get(jsonPath), Paths.get(jsonPath + ".old"), REPLACE_EXISTING);
            log.info("Migrated file '" + jsonPath + "' to '" + yamlPath + "'");
        }
    }

    return yamlFile;
}
 
开发者ID:Frederikam,项目名称:GensokyoBot,代码行数:35,代码来源:Config.java

示例8: dumpConfiguration

import org.yaml.snakeyaml.Yaml; //导入方法依赖的package包/类
private void dumpConfiguration(Path configFilePath) {
    try (FileWriter fileWriter = new FileWriter(configFilePath.toFile())) {
        DumperOptions options = new DumperOptions();
        options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);

        Representer representer = new Representer() {
            @Override
            protected NodeTuple representJavaBeanProperty(Object javaBean, Property property, Object propertyValue,Tag customTag) {
                // if value of property is null, ignore it.
                if (propertyValue == null) {
                    return null;
                }
                else {
                    return super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
                }
            }
        };

        representer.addClassTag(Configuration.class, Tag.MAP);

        Yaml yaml = new Yaml(representer, options);
        yaml.dump(configuration, fileWriter);
    } catch (IOException e) {
        throw new RuntimeException("Failed to dump configuration in file " + configFilePath, e);
    }
}
 
开发者ID:arquillian,项目名称:smart-testing,代码行数:27,代码来源:ProjectConfigurator.java

示例9: writeTo

import org.yaml.snakeyaml.Yaml; //导入方法依赖的package包/类
void writeTo(Path filePath) {
    DumperOptions options = new DumperOptions();
    options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
    options.setPrettyFlow(true);

    Yaml yaml = new Yaml(options);
    try {
        FileWriter writer = new FileWriter(filePath.toString());
        yaml.dump(properties, writer);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:arquillian,项目名称:smart-testing,代码行数:14,代码来源:ConfigurationFileBuilder.java

示例10: generate

import org.yaml.snakeyaml.Yaml; //导入方法依赖的package包/类
static String generate(Yaml yaml, PluginSpec from) throws Exception {
    Map<String, Object> data = new HashMap<>();
    data.put("main", from.getPluginClass());
    data.put("name", validateName(getName(from)));
    data.put("version", validateVersion(getVersion(from)));

    Putter<Pl, String, Object> putter = ifNotEmpty(from.getPl(), putter(data));
    putter.put("description", Pl::description);
    putter.put("authors", Pl::authors, a -> a.length != 0);
    putter.put("loadOn", y -> y.loadOn().name(), loadOn -> !loadOn.equals("POSTWORLD"));

    putter.put("depend", y -> Stream.of(y.depend())
                                    .filter(d -> !d.soft())
                                    .map(Dep::value)
                                    .collect(Collectors.toList()), list -> list.size() != 0);

    putter.put("softdepend", y -> Stream.of(y.depend())
                                        .filter(d -> d.soft())
                                        .map(Dep::value)
                                        .collect(Collectors.toList()), list -> list.size() != 0);
    putter.put("loadbefore", Pl::loadbefore, lb -> lb.length != 0);
    putter.put("prefix", Pl::prefix);
    putter.put("website", Pl::website);

    Map<String, Map<String, Object>> commandMap = new HashMap<>();
    putCommands(commandMap, from.getCommands());
    if (!commandMap.isEmpty())
        data.put("commands", commandMap);

    return yaml.dump(data);
}
 
开发者ID:Twister915,项目名称:pl,代码行数:32,代码来源:PluginYamlProducer.java

示例11: commandMapProducer

import org.yaml.snakeyaml.Yaml; //导入方法依赖的package包/类
public static String commandMapProducer(Yaml yaml, Map<String, Command> commandMap) {
    Map<String, Object> out = new HashMap<>();
    commandMap.forEach((name, data) ->
        out.put(name.toLowerCase(), ImmutableMap.builder()
                                                .put("handler", data.getHandlerClass())
                                                .build()));

    return yaml.dump(ImmutableMap.builder().put("commands", out).build());
}
 
开发者ID:Twister915,项目名称:pl,代码行数:10,代码来源:CommandMapProducer.java

示例12: parseToYml

import org.yaml.snakeyaml.Yaml; //导入方法依赖的package包/类
/**
 * Verify root format and parse to yml
 */
public static String parseToYml(Node root) {
    VALIDATOR.validate(root);

    RootYmlWrapper ymlWrapper = new RootYmlWrapper(new NodeWrapper(root));

    // clean property which not used in root
    ymlWrapper.flow.get(0).name = null;
    ymlWrapper.flow.get(0).allowFailure = null;

    Yaml yaml = new Yaml(ROOT_YML_CONSTRUCTOR, ORDERED_SKIP_EMPTY_REPRESENTER, DUMPER_OPTIONS);
    String dump = yaml.dump(ymlWrapper);
    dump = dump.substring(dump.indexOf(LINE_BREAK.getString()) + 1);
    return dump;
}
 
开发者ID:FlowCI,项目名称:flow-platform,代码行数:18,代码来源:NodeUtil.java

示例13: toFile

import org.yaml.snakeyaml.Yaml; //导入方法依赖的package包/类
public static <T> void toFile(T yamlObject, String fileName) throws IOException {
  Yaml yaml = new Yaml();
  yaml.dump(yamlObject, new FileWriter(fileName));
}
 
开发者ID:Microsoft,项目名称:pai,代码行数:5,代码来源:YamlUtils.java

示例14: toYaml

import org.yaml.snakeyaml.Yaml; //导入方法依赖的package包/类
public static String toYaml(Object o) {
	Yaml yaml = new Yaml();
	return yaml.dump(o);
}
 
开发者ID:21ca,项目名称:selenium-testng-template,代码行数:5,代码来源:FileUtils.java

示例15: marshal

import org.yaml.snakeyaml.Yaml; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 *
 * @see marshalsec.MarshallerBase#marshal(java.lang.Object)
 */
@Override
public String marshal ( Object o ) throws Exception {
    Yaml r = new Yaml();
    return r.dump(o);
}
 
开发者ID:mbechler,项目名称:marshalsec,代码行数:11,代码来源:SnakeYAML.java


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