gpt4 book ai didi

com.esotericsoftware.yamlbeans.YamlWriter类的使用及代码示例

转载 作者:知者 更新时间:2024-03-15 16:08:40 27 4
gpt4 key购买 nike

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

YamlWriter介绍

[英]Serializes Java objects as YAML.
[中]将Java对象序列化为YAML。

代码示例

代码示例来源:origin: FlowCI/flow-platform

/**
   * T to Yml
   *
   * @param t object
   * @return String
   */
  public static <T> String toYml(T t) {
    Map<String, Object> map = new HashMap<>();
    Object o = toObject(t);
    map.put("flow", o);
    String yml;

    try (Writer stringWriter = new StringWriter()) {
      YamlWriter writer = new YamlWriter(stringWriter, yamlConfig);
      writer.write(map);
      yml = stringWriter.toString();
    } catch (Throwable throwable) {
      throw new YmlParseException(YML_CONVERT_MESSAGE, throwable);
    }

    return yml;
  }
}

代码示例来源:origin: EsotericSoftware/yamlbeans

public void write (Object object) throws YamlException {
  if (config.writeConfig.autoAnchor) {
    countObjectReferences(object);
    queuedObjects.add(object);
    return;
  }
  writeInternal(object);
}

代码示例来源:origin: org.lorislab.hugoup/hugoup

public static void writeFile(String file, Object data) throws Exception {
    YamlConfig yamlConfig = new YamlConfig();
    yamlConfig.writeConfig.setWriteClassname(YamlConfig.WriteClassName.NEVER);
    YamlWriter writer = new YamlWriter(new FileWriter(file), yamlConfig);
    writer.write(data);
    writer.close();        
  }
}

代码示例来源:origin: audit4j/audit4j-core

/**
 * {@inheritDoc}
 * 
 */
@Override
public void generateConfig(T config, String filePath) throws ConfigurationException {
  YamlWriter writer;
  try {
    writer = new YamlWriter(new FileWriter(filePath));
    writer.getConfig().setClassTag(clazz.getSimpleName(), clazz);
    writer.write(Configuration.DEFAULT);
    writer.close();
  } catch (IOException e) {
    throw new ConfigurationException("Configuration Exception", "CONF_002");
  }
}

代码示例来源:origin: com.esotericsoftware.yamlbeans/yamlbeans

/** Finishes writing any buffered output and releases all resources.
 * @throws YamlException If the buffered output could not be written or the writer could not be closed. */
public void close () throws YamlException {
  clearAnchors();
  defaultValuePrototypes.clear();
  try {
    emitter.emit(Event.STREAM_END);
    emitter.close();
  } catch (EmitterException ex) {
    throw new YamlException(ex);
  } catch (IOException ex) {
    throw new YamlException(ex);
  }
}

代码示例来源:origin: com.esotericsoftware.yamlbeans/yamlbeans

countObjectReferences(item);
return;
  countObjectReferences(value);
return;
  countObjectReferences(Array.get(object, i));
return;
  throw new YamlException("Error getting property '" + property + "' on class: " + object.getClass().getName(), ex);
countObjectReferences(propertyValue);

代码示例来源:origin: org.lorislab.hugoup/hugoup

public static String toString(Object data) throws Exception {
  YamlConfig yamlConfig = new YamlConfig();
  yamlConfig.writeConfig.setWriteClassname(YamlConfig.WriteClassName.NEVER);
  StringWriter w = new StringWriter();
  YamlWriter writer = new YamlWriter(w, yamlConfig);
  writer.write(data);
  writer.close();          
  return w.toString();
}

代码示例来源:origin: EsotericSoftware/yamlbeans

/** Finishes writing any buffered output and releases all resources.
 * @throws YamlException If the buffered output could not be written or the writer could not be closed. */
public void close () throws YamlException {
  clearAnchors();
  defaultValuePrototypes.clear();
  try {
    emitter.emit(Event.STREAM_END);
    emitter.close();
  } catch (EmitterException ex) {
    throw new YamlException(ex);
  } catch (IOException ex) {
    throw new YamlException(ex);
  }
}

代码示例来源:origin: EsotericSoftware/yamlbeans

countObjectReferences(item);
return;
  countObjectReferences(value);
return;
  countObjectReferences(Array.get(object, i));
return;
  throw new YamlException("Error getting property '" + property + "' on class: " + object.getClass().getName(), ex);
countObjectReferences(propertyValue);

代码示例来源:origin: dariober/ASCIIGenome

YamlWriter writer = new YamlWriter(new FileWriter(outYaml));
writer.write(asciigenome_history);
writer.close();

代码示例来源:origin: mbechler/marshalsec

/**
 * {@inheritDoc}
 *
 * @see marshalsec.MarshallerBase#marshal(java.lang.Object)
 */
@Override
public String marshal ( Object o ) throws Exception {
  YamlConfig yc = new YamlConfig();
  StringWriter sw = new StringWriter();
  YamlWriter w = new YamlWriter(sw, yc);
  w.write(o);
  return sw.toString();
}

代码示例来源:origin: com.esotericsoftware.yamlbeans/yamlbeans

public void write (Object object) throws YamlException {
  if (config.writeConfig.autoAnchor) {
    countObjectReferences(object);
    queuedObjects.add(object);
    return;
  }
  writeInternal(object);
}

代码示例来源:origin: org.cloudfoundry/cloudfoundry-client-lib

protected void saveTokensToFile(TargetInfos targetInfos) {
  final File tokensFile = getTokensFile();
  tokensFile.getParentFile().mkdirs();
  try {
    FileWriter fileWriter = new FileWriter(tokensFile);
    YamlConfig config = new YamlConfig();
    config.writeConfig.setAlwaysWriteClassname(false);
    config.writeConfig.setWriteRootElementTags(false);
    config.writeConfig.setWriteRootTags(false);
    config.writeConfig.setExplicitFirstDocument(true);
    YamlWriter yamlWriter = new YamlWriter(fileWriter, config);
    yamlWriter.write(targetInfos);
    yamlWriter.close();
    fileWriter.close();
  } catch (IOException e) {
    throw new RuntimeException("An error occurred writing the tokens file at " +
        tokensFile.getPath() + ":" + e.getMessage(), e);
  }
}

代码示例来源:origin: stackoverflow.com

// let YamlWriter write its contents to an in-memory buffer
 StringWriter temp = new StringWriter();
 YamlWriter yamlOut = new YamlWriter(temp);
 yamlOut.write(someObject);
 // then dump the in-memory buffer out to a file, manipulating lines that
 // start with a dash
 PrintWriter out = new PrintWriter(new FileWriter(new File("someoutput.dat")));
 LineNumberReader in = new LineNumberReader(new StringReader(temp.toString()));
 String line;
 while ((line = in.readLine()) != null) {
   if (line.startsWith("-")) {
     line = line.substring(1);
   }
   out.println(line);
 }

代码示例来源:origin: com.sap.cloud.lm.sl/cloudfoundry-client-lib

protected void saveTokensToFile(TargetInfos targetInfos) {
    final File tokensFile = getTokensFile();
    tokensFile.getParentFile()
      .mkdirs();
    try {
      FileWriter fileWriter = new FileWriter(tokensFile);

      YamlConfig config = new YamlConfig();
      config.writeConfig.setAlwaysWriteClassname(false);
      config.writeConfig.setWriteRootElementTags(false);
      config.writeConfig.setWriteRootTags(false);
      config.writeConfig.setExplicitFirstDocument(true);
      YamlWriter yamlWriter = new YamlWriter(fileWriter, config);

      yamlWriter.write(targetInfos);

      yamlWriter.close();
      fileWriter.close();
    } catch (IOException e) {
      throw new RuntimeException("An error occurred writing the tokens file at " + tokensFile.getPath() + ":" + e.getMessage(), e);
    }
  }
}

代码示例来源:origin: stackoverflow.com

YamlWriter writer = new YamlWriter(w);
writer.write(p1);
writer.close();

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com