leap.lang.yaml.YAML类的使用及代码示例

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

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

YAML介绍

暂无

代码示例

代码示例来源:origin: org.leapframework/leap-lang

/**
 * Parse the yaml content to {@link YamlValue}.
 */
public static YamlValue parse(Reader reader) throws YamlException {
  return YamlValue.of(decode(reader));
}

代码示例来源:origin: org.leapframework/leap-core

@Override
public boolean readProperties(AppPropertyContext context, Resource resource) {
  String filename = resource.getFilename();
  if(Strings.endsWithIgnoreCase(filename, ".yaml") || Strings.endsWithIgnoreCase(filename,".yml")) {
    String content = resource.getContent();
    if(Strings.isEmpty(content)) {
      return true;
    }
    Map<String, Object> map = YAML.parse(content).asMap();
    if(map.isEmpty()) {
      return true;
    }
    Map<String, String> props = Maps.toProperties(map);
    props.forEach((key, value) -> putProperty(context, resource, key, value));
    return true;
  }
  return false;
}

代码示例来源:origin: org.leapframework/leap-lang

/**
 * Parse the yaml content to {@link YamlValue}.
 */
public static YamlValue parse(String string) throws YamlException {
  return YamlValue.of(decode(string));
}

代码示例来源:origin: org.leapframework/jmms-plugins-swagger-doc

public SwaggerDoc(String dir) {
  this.dir = leap.lang.path.Paths.suffixWithSlash(dir);
  Map map = null;
  File swaggerFile = Paths.get(dir).resolve("./swagger.json").toFile();
  if(swaggerFile.exists()) {
    map = JSON.decodeMap(IO.readString(swaggerFile, Charsets.UTF_8));
  }else {
    swaggerFile = Paths.get(dir).resolve("./swagger.yaml").toFile();
    if(swaggerFile.exists()) {
      map = YAML.decode(Resources.createFileResource(swaggerFile).getContent());
    }
  }
  if(null != map) {
    this.swagger = JsonObject.of(map);
  }
}

代码示例来源:origin: org.leapframework/leap-webapi

@Override
public ApiMetadataBuilder read(Reader reader) throws IOException {
  String content = IO.readString(reader).trim();
  Map<String,Object> swagger;
  if(content.startsWith("{")) {
    swagger = JSON.decode(content);
  }else{
    swagger = YAML.decode(content);
  }
  ApiMetadataBuilder m = new ApiMetadataBuilder();
  readSwagger(swagger, m);
  return m;
}

代码示例来源:origin: org.leapframework/leap-core

protected void readMessages(MessageContext context, Resource resource) {
  try {
    String localeName = Locales.extractFromFilename(resource.getFilename());
    Locale locale     = Strings.isEmpty(localeName) ? null : Locales.forName(localeName);
    Map<String, String> props;
    try (Reader reader = resource.getInputStreamReader(charset)) {
      Map map = YAML.decode(reader);
      if (null == map || map.isEmpty()) {
        return;
      }
      props = Maps.toProperties(map);
    }
    for (String key : props.keySet()) {
      readMessage(context, resource, locale, props, (String) key);
    }
  } catch (Exception e) {
    throw new AppConfigException("Error reading messages from properties resource [" +
        resource.getURLString() + "], " + e.getMessage(), e);
  }
}

相关文章

微信公众号

最新文章

更多

YAML类方法