private static void dumpYaml(TopologyDef topology, Yaml yaml) { System.out.println("Configuration (interpreted): \n" + yaml.dump(topology)); }
/** * dumps a conf map into a file, note that the output yaml file uses a compact format * e.g., for a list, it uses key: [xx, xx] instead of multiple lines. */ public static void dumpYaml(Map conf, String file) { Yaml yaml = new Yaml(); try { Writer writer = new OutputStreamWriter(new FileOutputStream(file), "UTF-8"); yaml.dump(conf, writer); } catch (Exception ex) { LOG.error("Error:", ex); } }
/** * Saves this PluginDescriptionFile to the given writer * * @param writer Writer to output this file to */ public void save(Writer writer) { YAML.get().dump(saveMap(), writer); }
public void updateAutoBootstrap(String yamlFile, boolean autobootstrap) throws IOException { DumperOptions options = new DumperOptions(); options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); Yaml yaml = new Yaml(options); @SuppressWarnings("rawtypes") Map map = yaml.load(new FileInputStream(yamlFile)); // Dont bootstrap in restore mode map.put("auto_bootstrap", autobootstrap); if (logger.isInfoEnabled()) { logger.info("Updating yaml: " + yaml.dump(map)); } yaml.dump(map, new FileWriter(yamlFile)); }
/** * Convert this into a YAML String. * @return this as a YAML String. */ public String toYamlString() { Yaml yaml = new Yaml(new SafeConstructor()); StringWriter writer = new StringWriter(); yaml.dump(toConf(), writer); return writer.toString(); }
public void writeToYmlSettingsFile(File file) { DumperOptions dumperOptions = new DumperOptions(); dumperOptions.setPrettyFlow(true); dumperOptions.setDefaultFlowStyle(BLOCK); Yaml yaml = new Yaml(dumperOptions); String output = ELASTICSEARCH_YML_OPTIONS_HEADER + yaml.dump(elasticsearchSettings); try { Files.write(file.toPath(), output.getBytes(StandardCharsets.UTF_8)); } catch (IOException e) { throw new IllegalStateException("Cannot write Elasticsearch yml settings file", e); } } }
/** * Write this out to a file in YAML format. * @param file the file to write to. * @throws IOException if there is an error writing to the file. */ public void writeTo(File file) throws IOException { Yaml yaml = new Yaml(new SafeConstructor()); try (FileWriter writer = new FileWriter(file)) { yaml.dump(toConf(), writer); } }
public void save(Writer output) { DumperOptions options = new DumperOptions(); options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); getYaml().dump(this, output); }
public void writeSidebar(Map<String, Object> sidebar) throws IOException { DumperOptions options = new DumperOptions(); options.setDefaultFlowStyle(FlowStyle.BLOCK); if (SystemUtils.IS_OS_WINDOWS) { options.setLineBreak(LineBreak.WIN); } Yaml yaml = new Yaml(options); writer.write(sidebarPath, Arrays.asList(yaml.dump(sidebar))); System.out.println("Generated " + sidebarPath); } }
public <T> T testRoundTrip(T in) throws Exception { String output = yaml.dump(in); logger.debug(output); return (T) yaml.load(output); }
public static void main(String[] args) { DumperOptions options = new DumperOptions(); options.setIndent(4); options.setDefaultFlowStyle(FlowStyle.BLOCK); Yaml yaml = new Yaml(options); String dump = yaml.dump(new PerfBenchmarkDriverConf()); System.out.println(dump); } }
private String dumpResumeStateInYaml(final ResumeState modelObject) { final ModelManager modelManager = this.embed.getModelManager(); final Object object = modelManager.readObject(Object.class, modelManager.writeObject(modelObject)); return (new org.yaml.snakeyaml.Yaml()).dump(object); }
private String dumpDataSourceInYaml(final DataSource modelObject) { final ModelManager modelManager = this.embed.getModelManager(); final Object object = modelManager.readObject(Object.class, modelManager.writeObject(modelObject)); return (new org.yaml.snakeyaml.Yaml()).dump(object); }
@Override @Signature public Memory format(Environment env, Memory... args) { try { return StringMemory.valueOf(yaml.dump(Memory.unwrap(env, args[0], true))); } catch (YAMLException e) { env.exception(ProcessorException.class, e.getMessage()); return Memory.NULL; } }
@Override @Signature public Memory formatTo(Environment env, Memory... args) { try { yaml.dump( Memory.unwrap(env, args[0], true), new OutputStreamWriter(Stream.getOutputStream(env, args[1]), env.getDefaultCharset()) ); return Memory.NULL; } catch (YAMLException e) { env.exception(ProcessorException.class, e.getMessage()); return Memory.NULL; } } }
public static <K extends Comparable<? super K>, V extends Object> String prettyPrintYaml(Map<K,V> map) { DumperOptions dump = new DumperOptions(); dump.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); dump.setPrettyFlow(true); dump.setIndent(2); dump.setCanonical(false); dump.setExplicitStart(true); Yaml yaml = new Yaml(dump); return yaml.dump(sortByKeys(map)); }
@Override public String saveToString() { yamlOptions.setIndent(options().indent()); yamlOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); yamlOptions.setAllowUnicode(SYSTEM_UTF); yamlRepresenter.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); String header = buildHeader(); String dump = yaml.dump(getValues(false)); if (dump.equals(BLANK_CONFIG)) { dump = ""; } return header + dump; }
public Map<String, Object> getYamlConfig(Resource resource) { YamlMapFactoryBean factory = new YamlMapFactoryBean(); factory.setResolutionMethod(YamlProcessor.ResolutionMethod.OVERRIDE_AND_IGNORE); factory.setResources(new Resource[] {resource}); Map<String, Object> result = factory.getObject(); String yamlStr = (new Yaml()).dump(result); result.put(RAW_YAML, yamlStr); return result; }
@Override public org.springframework.core.env.PropertySource<?> createPropertySource(String name, EncodedResource resource) { YamlMapFactoryBean factory = new YamlMapFactoryBean(); factory.setResolutionMethod(YamlProcessor.ResolutionMethod.OVERRIDE_AND_IGNORE); factory.setResources(new Resource[]{resource.getResource()}); Map<String, Object> yamlMap = factory.getObject(); String yamlStr = (new Yaml()).dump(yamlMap); yamlMap.put("environmentYamlKey", yamlStr); return new NestedMapPropertySource("servletConfigYaml", yamlMap); } }
@Override public org.springframework.core.env.PropertySource<?> createPropertySource(String name, EncodedResource resource) { YamlMapFactoryBean factory = new YamlMapFactoryBean(); factory.setResolutionMethod(YamlProcessor.ResolutionMethod.OVERRIDE_AND_IGNORE); factory.setResources(new Resource[]{resource.getResource()}); Map<String, Object> yamlMap = factory.getObject(); String yamlStr = (new Yaml()).dump(yamlMap); yamlMap.put("environmentYamlKey", yamlStr); return new NestedMapPropertySource("servletConfigYaml", yamlMap); } }