public void write(Writer output, Map<String, Object> o, Model model) throws IOException { //TODO improve SnakeYAML API (A. Somov) DumperOptions dumperOptions = new DumperOptions(); dumperOptions.setIndent(2); dumperOptions.setWidth(80); Serializer serializer = new Serializer(new Emitter(output, dumperOptions), new ModelResolver(), dumperOptions, Tag.MAP); Representer representer = new ModelRepresenter(); try { serializer.open(); Node node = representer.represent(model); serializer.serialize(node); serializer.close(); } catch (IOException e) { throw new YAMLException(e); } } }
@Override public String saveToString() { // Some reflection wizardly to avoid having a lot of linebreaks in the yaml file, and get a "footer" into the file. // TODO: Interesting, but review this: still necessary/useful in CB-1.4 ?. try { Field op; op = YamlConfiguration.class.getDeclaredField("yamlOptions"); op.setAccessible(true); final DumperOptions options = (DumperOptions) op.get(this); options.setWidth(200); } catch (final Exception e) {} return super.saveToString(); }
private void saveFile() { DumperOptions options = new DumperOptions(); options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); options.setWidth(99999999); options.setAllowUnicode(true); try { Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8")); try { new Yaml(options).dump(language, out); for (String comment : comments) { out.write(comment); } } finally { out.close(); } } catch (IOException e) { // could not save e.printStackTrace(); } }
/** * Convenience for {@link #build(Consumer)} to generate simple YAML in * a single line. */ public static Consumer<DumperOptions> inOneLine() { return dumper -> { dumper.setDefaultFlowStyle(FLOW); dumper.setDefaultScalarStyle(PLAIN); dumper.setWidth(Integer.MAX_VALUE); }; }
public synchronized String toString() { DumperOptions options = new DumperOptions(); options.setWidth(50); options.setIndent(4); options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); Yaml yaml = new Yaml(options); return yaml.dump(map); }
private void saveFile() { DumperOptions options = new DumperOptions(); options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); options.setWidth(99999999); options.setAllowUnicode(true); FileWriter fw = null; try { fw = new FileWriter(file); StringWriter writer = new StringWriter(); new Yaml(options).dump(language, writer); for (String comment : comments) { fw.write(comment); } fw.write(writer.toString()); } catch (IOException e) { // could not save e.printStackTrace(); } finally{ try { fw.close(); } catch (IOException e) { e.printStackTrace(); } } }
/** * Create a new YamlCerealEngine object with the requested output flow style and indent width. * * @param useBlockFlow * if <code>true</code>, any output YAML will use block flow which is easier to read, * but potentially can take up more data * @param indentWidth * the indent width */ public YamlCerealEngine(boolean useBlockFlow, int indentWidth) { DumperOptions options = new DumperOptions(); options.setWidth(100); options.setIndent(indentWidth); options.setDefaultFlowStyle(useBlockFlow ? BLOCK : AUTO); this.yaml = new Yaml(options); }
@JRubyMethod(name = "line_width=") public IRubyObject line_width_set(ThreadContext context, IRubyObject width) { options.setWidth((int)width.convertToInteger().getLongValue()); return width; }
@JRubyMethod(name = "line_width=") public IRubyObject line_width_set(ThreadContext context, IRubyObject width) { options.setWidth((int)width.convertToInteger().getLongValue()); return width; }
public void write( Writer output, Map<String, Object> o, Model model ) throws IOException { DumperOptions options = new DumperOptions(); options.setExplicitRoot( Tags.MAP ); options.setDefaultFlowStyle( FlowStyle.AUTO ); options.setIndent( 2 ); options.setWidth( 80 ); Representer representer = new ModelRepresenter(); Dumper dumper = new Dumper( representer, options ); Yaml yaml = new Yaml( dumper ); yaml.dump( model, output ); }
public void write( Writer output, Map<String, Object> o, Model model ) throws IOException { DumperOptions options = new DumperOptions(); options.setExplicitRoot( Tags.MAP ); options.setDefaultFlowStyle( FlowStyle.AUTO ); options.setIndent( 2 ); options.setWidth( 80 ); Representer representer = new ModelRepresenter(); Dumper dumper = new Dumper( representer, options ); Yaml yaml = new Yaml( dumper ); yaml.dump( model, output ); }
private Yaml getYaml() { Representer representer = new TapeRepresenter(fileResolver); representer.addClassTag(YamlTape.class, YamlTape.TAPE_TAG); Constructor constructor = new TapeConstructor(fileResolver); constructor.addTypeDescription(new TypeDescription(YamlTape.class, YamlTape.TAPE_TAG)); DumperOptions dumperOptions = new DumperOptions(); dumperOptions.setDefaultFlowStyle(BLOCK); dumperOptions.setWidth(256); Yaml yaml = new Yaml(constructor, representer, dumperOptions); yaml.setBeanAccess(BeanAccess.FIELD); return yaml; }
private static Yaml getYaml() { Representer representer = new TapeRepresenter(); representer.addClassTag(YamlTape.class, YamlTape.TAPE_TAG); Constructor constructor = new TapeConstructor(); constructor.addTypeDescription(new TypeDescription(YamlTape.class, YamlTape.TAPE_TAG)); DumperOptions dumperOptions = new DumperOptions(); dumperOptions.setDefaultFlowStyle(BLOCK); dumperOptions.setWidth(256); Yaml yaml = new Yaml(constructor, representer, dumperOptions); yaml.setBeanAccess(BeanAccess.FIELD); return yaml; } }
private static Yaml getYaml() { Representer representer = new TapeRepresenter(); representer.addClassTag(YamlTape.class, YamlTape.TAPE_TAG); Constructor constructor = new TapeConstructor(); constructor.addTypeDescription(new TypeDescription(YamlTape.class, YamlTape.TAPE_TAG)); DumperOptions dumperOptions = new DumperOptions(); dumperOptions.setDefaultFlowStyle(BLOCK); dumperOptions.setWidth(256); Yaml yaml = new Yaml(constructor, representer, dumperOptions); yaml.setBeanAccess(BeanAccess.FIELD); return yaml; } }
private YamlFormatter(Builder builder) { options = new DumperOptions(); options.setExplicitStart(builder.explicitStart); options.setExplicitEnd(builder.explicitEnd); options.setIndent(builder.indent); options.setWidth(builder.lineLength); options.setDefaultFlowStyle(builder.flowStyle); options.setPrettyFlow(builder.prettyFlow); options.setDefaultScalarStyle(builder.scalarStyle); }
@JRubyMethod(visibility = PRIVATE) public IRubyObject initialize(ThreadContext context, IRubyObject io, IRubyObject rbOptions) { IRubyObject width = rbOptions.callMethod(context, "line_width"); IRubyObject canonical = rbOptions.callMethod(context, "canonical"); IRubyObject level = rbOptions.callMethod(context, "indentation"); options = new DumperOptions(); options.setCanonical(canonical.isTrue()); options.setIndent((int)level.convertToInteger().getLongValue()); options.setWidth((int)width.convertToInteger().getLongValue()); this.io = io; return context.nil; }
@JRubyMethod(visibility = PRIVATE) public IRubyObject initialize(ThreadContext context, IRubyObject io, IRubyObject rbOptions) { IRubyObject width = rbOptions.callMethod(context, "line_width"); IRubyObject canonical = rbOptions.callMethod(context, "canonical"); IRubyObject level = rbOptions.callMethod(context, "indentation"); options = new DumperOptions(); options.setCanonical(canonical.isTrue()); options.setIndent((int)level.convertToInteger().getLongValue()); options.setWidth((int)width.convertToInteger().getLongValue()); this.io = io; return context.nil; }
public void write(Writer output, Map<String, Object> o, Model model) throws IOException { //TODO improve SnakeYAML API (A. Somov) DumperOptions dumperOptions = new DumperOptions(); dumperOptions.setIndent(2); dumperOptions.setWidth(80); Serializer serializer = new Serializer(new Emitter(output, dumperOptions), new ModelResolver(), dumperOptions, Tag.MAP); Representer representer = new ModelRepresenter(); try { serializer.open(); Node node = representer.represent(model); serializer.serialize(node); serializer.close(); } catch (IOException e) { throw new YAMLException(e); } } }