io.jenkins.plugins.casc.snakeyaml.Yaml类的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(6.6k)|赞(0)|评价(0)|浏览(266)

本文整理了Java中io.jenkins.plugins.casc.snakeyaml.Yaml类的一些代码示例,展示了Yaml类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Yaml类的具体详情如下:
包路径:io.jenkins.plugins.casc.snakeyaml.Yaml
类名称:Yaml

Yaml介绍

[英]Public YAML interface. Each Thread must have its own instance.
[中]公共YAML接口。每个线程都必须有自己的实例。

代码示例

代码示例来源:origin: jenkinsci/configuration-as-code-plugin

  1. private static Stream<? extends Map.Entry<String, Object>> entries(Reader config) {
  2. return ((Map<String, Object>) new Yaml().loadAs(config, Map.class)).entrySet().stream();
  3. }

代码示例来源:origin: jenkinsci/configuration-as-code-plugin

  1. /**
  2. * Serialize a sequence of Java objects into a YAML stream.
  3. *
  4. * @param data
  5. * Iterator with Objects
  6. * @param output
  7. * stream to write to
  8. */
  9. public void dumpAll(Iterator<? extends Object> data, Writer output) {
  10. dumpAll(data, output, null);
  11. }

代码示例来源:origin: jenkinsci/configuration-as-code-plugin

  1. /**
  2. * <p>
  3. * Serialize a Java object into a YAML string. Override the default root tag
  4. * with <code>Tag.MAP</code>.
  5. * </p>
  6. * <p>
  7. * This method is similar to <code>Yaml.dump(data)</code> except that the
  8. * root tag for the whole document is replaced with <code>Tag.MAP</code> tag
  9. * (implicit !!map).
  10. * </p>
  11. * <p>
  12. * Block Mapping is used as the collection style. See 10.2.2. Block Mappings
  13. * (http://yaml.org/spec/1.1/#id934537)
  14. * </p>
  15. *
  16. * @param data
  17. * Java object to be serialized to YAML
  18. * @return YAML String
  19. */
  20. public String dumpAsMap(Object data) {
  21. return dumpAs(data, Tag.MAP, FlowStyle.BLOCK);
  22. }

代码示例来源:origin: jenkinsci/configuration-as-code-plugin

  1. /**
  2. * Parse the only YAML document in a stream and produce the corresponding
  3. * Java object.
  4. *
  5. * @param io
  6. * data to load from (BOM must not be present)
  7. * @param <T>
  8. * the class of the instance to be created
  9. * @return parsed object
  10. */
  11. @SuppressWarnings("unchecked")
  12. public <T> T load(Reader io) {
  13. return (T) loadFromReader(new StreamReader(io), Object.class);
  14. }

代码示例来源:origin: jenkinsci/configuration-as-code-plugin

  1. /**
  2. * Parse all YAML documents in a String and produce corresponding Java
  3. * objects. (Because the encoding in known BOM is not respected.) The
  4. * documents are parsed only when the iterator is invoked.
  5. *
  6. * @param yaml
  7. * YAML data to load from (BOM must not be present)
  8. * @return an Iterable over the parsed Java objects in this String in proper
  9. * sequence
  10. */
  11. public Iterable<Object> loadAll(String yaml) {
  12. return loadAll(new StringReader(yaml));
  13. }

代码示例来源:origin: jenkinsci/configuration-as-code-plugin

  1. /**
  2. * Create Yaml instance. It is safe to create a few instances and use them
  3. * in different Threads.
  4. *
  5. * @param constructor
  6. * BaseConstructor to construct incoming documents
  7. * @param representer
  8. * Representer to emit outgoing objects
  9. */
  10. public Yaml(BaseConstructor constructor, Representer representer) {
  11. this(constructor, representer, initDumperOptions(representer));
  12. }

代码示例来源:origin: jenkinsci/configuration-as-code-plugin

  1. /**
  2. * Parse the only YAML document in a String and produce the corresponding
  3. * Java object. (Because the encoding in known BOM is not respected.)
  4. *
  5. * @param <T>
  6. * Class is defined by the second argument
  7. * @param yaml
  8. * YAML data to load from (BOM must not be present)
  9. * @param type
  10. * Class of the object to be created
  11. * @return parsed object
  12. */
  13. @SuppressWarnings("unchecked")
  14. public <T> T loadAs(String yaml, Class<T> type) {
  15. return (T) loadFromReader(new StreamReader(yaml), type);
  16. }

代码示例来源:origin: jenkinsci/configuration-as-code-plugin

  1. /**
  2. * Parse all YAML documents in a stream and produce corresponding Java
  3. * objects. The documents are parsed only when the iterator is invoked.
  4. *
  5. * @param yaml
  6. * YAML data to load from (BOM is respected to detect encoding and removed from the data)
  7. * @return an Iterable over the parsed Java objects in this stream in proper
  8. * sequence
  9. */
  10. public Iterable<Object> loadAll(InputStream yaml) {
  11. return loadAll(new UnicodeReader(yaml));
  12. }

代码示例来源:origin: io.jenkins/configuration-as-code

  1. private static Stream<? extends Map.Entry<String, Object>> entries(Reader config) {
  2. return ((Map<String, Object>) new Yaml().loadAs(config, Map.class)).entrySet().stream();
  3. }

代码示例来源:origin: jenkinsci/configuration-as-code-plugin

  1. /**
  2. * Parse the only YAML document in a String and produce the corresponding
  3. * Java object. (Because the encoding in known BOM is not respected.)
  4. *
  5. * @param yaml
  6. * YAML data to load from (BOM must not be present)
  7. * @param <T>
  8. * the class of the instance to be created
  9. * @return parsed object
  10. */
  11. @SuppressWarnings("unchecked")
  12. public <T> T load(String yaml) {
  13. return (T) loadFromReader(new StreamReader(yaml), Object.class);
  14. }

代码示例来源:origin: jenkinsci/configuration-as-code-plugin

  1. /**
  2. * Serialize a sequence of Java objects into a YAML String.
  3. *
  4. * @param data
  5. * Iterator with Objects
  6. * @return YAML String with all the objects in proper sequence
  7. */
  8. public String dumpAll(Iterator<? extends Object> data) {
  9. StringWriter buffer = new StringWriter();
  10. dumpAll(data, buffer, null);
  11. return buffer.toString();
  12. }

代码示例来源:origin: jenkinsci/configuration-as-code-plugin

  1. /**
  2. * Parse the only YAML document in a stream and produce the corresponding
  3. * Java object.
  4. *
  5. * @param <T>
  6. * Class is defined by the second argument
  7. * @param io
  8. * data to load from (BOM must not be present)
  9. * @param type
  10. * Class of the object to be created
  11. * @return parsed object
  12. */
  13. @SuppressWarnings("unchecked")
  14. public <T> T loadAs(Reader io, Class<T> type) {
  15. return (T) loadFromReader(new StreamReader(io), type);
  16. }

代码示例来源:origin: jenkinsci/configuration-as-code-plugin

  1. /**
  2. * Serialize a Java object into a YAML String.
  3. *
  4. * @param data
  5. * Java object to be Serialized to YAML
  6. * @return YAML String
  7. */
  8. public String dump(Object data) {
  9. List<Object> list = new ArrayList<Object>(1);
  10. list.add(data);
  11. return dumpAll(list.iterator());
  12. }

代码示例来源:origin: jenkinsci/configuration-as-code-plugin

  1. /**
  2. * Parse the only YAML document in a stream and produce the corresponding
  3. * Java object.
  4. *
  5. * @param io
  6. * data to load from (BOM is respected to detect encoding and removed from the data)
  7. * @param <T>
  8. * the class of the instance to be created
  9. * @return parsed object
  10. */
  11. @SuppressWarnings("unchecked")
  12. public <T> T load(InputStream io) {
  13. return (T) loadFromReader(new StreamReader(new UnicodeReader(io)), Object.class);
  14. }

代码示例来源:origin: jenkinsci/configuration-as-code-plugin

  1. /**
  2. * Serialize a Java object into a YAML stream.
  3. *
  4. * @param data
  5. * Java object to be serialized to YAML
  6. * @param output
  7. * stream to write to
  8. */
  9. public void dump(Object data, Writer output) {
  10. List<Object> list = new ArrayList<Object>(1);
  11. list.add(data);
  12. dumpAll(list.iterator(), output, null);
  13. }

代码示例来源:origin: jenkinsci/configuration-as-code-plugin

  1. /**
  2. * Parse the only YAML document in a stream and produce the corresponding
  3. * Java object.
  4. *
  5. * @param <T>
  6. * Class is defined by the second argument
  7. * @param input
  8. * data to load from (BOM is respected to detect encoding and removed from the data)
  9. * @param type
  10. * Class of the object to be created
  11. * @return parsed object
  12. */
  13. @SuppressWarnings("unchecked")
  14. public <T> T loadAs(InputStream input, Class<T> type) {
  15. return (T) loadFromReader(new StreamReader(new UnicodeReader(input)), type);
  16. }

代码示例来源:origin: jenkinsci/configuration-as-code-plugin

  1. list.add(data);
  2. StringWriter buffer = new StringWriter();
  3. dumpAll(list.iterator(), buffer, rootTag);
  4. representer.setDefaultFlowStyle(oldStyle);
  5. return buffer.toString();

相关文章