gpt4 book ai didi

org.yaml.snakeyaml.Yaml.load()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-18 05:18:40 25 4
gpt4 key购买 nike

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

Yaml.load介绍

[英]Parse the only YAML document in a stream and produce the corresponding Java object.
[中]解析流中唯一的YAML文档并生成相应的Java对象。

代码示例

代码示例来源:origin: apache/incubator-shardingsphere

@SuppressWarnings("unchecked")
  @Override
  public Map<String, Object> load(final String data) {
    return Strings.isNullOrEmpty(data) ? new LinkedHashMap<String, Object>() : (Map) new Yaml().load(data);
  }
}

代码示例来源:origin: apache/incubator-shardingsphere

@SuppressWarnings("unchecked")
  @Override
  public Map<String, DataSourceConfiguration> load(final String data) {
    Map<String, YamlDataSourceConfiguration> result = (Map) new Yaml().load(data);
    Preconditions.checkState(null != result && !result.isEmpty(), "No available data sources to load for orchestration.");
    return Maps.transformValues(result, new Function<YamlDataSourceConfiguration, DataSourceConfiguration>() {
      
      @Override
      public DataSourceConfiguration apply(final YamlDataSourceConfiguration input) {
        DataSourceConfiguration result = new DataSourceConfiguration(input.getDataSourceClassName());
        result.getProperties().putAll(input.getProperties());
        return result;
      }
    });
  }
}

代码示例来源:origin: pmd/pmd

public Map<String, Object> loadSidebar() throws IOException {
  try (Reader reader = Files.newBufferedReader(sidebarPath, StandardCharsets.UTF_8)) {
    Yaml yaml = new Yaml();
    @SuppressWarnings("unchecked")
    Map<String, Object> sidebar = (Map<String, Object>) yaml.load(reader);
    return sidebar;
  }
}

代码示例来源:origin: alibaba/jstorm

public static void LoadYaml(String confPath) {
  
  Yaml yaml = new Yaml();
  
  try {
    InputStream stream = new FileInputStream(confPath);
    
    conf = (Map) yaml.load(stream);
    if (conf == null || conf.isEmpty() == true) {
      throw new RuntimeException("Failed to read config file");
    }
    
  } catch (FileNotFoundException e) {
    System.out.println("No such file " + confPath);
    throw new RuntimeException("No config file");
  } catch (Exception e1) {
    e1.printStackTrace();
    throw new RuntimeException("Failed to read config file");
  }
  
  return;
}

代码示例来源:origin: alibaba/jstorm

private static Map LoadYaml(String confPath) {
  Map ret = null;
  Yaml yaml = new Yaml();
  try {
    InputStream stream = new FileInputStream(confPath);
    ret = (Map) yaml.load(stream);
    if (ret == null || ret.isEmpty() == true) {
      throw new RuntimeException("Failed to read config file");
    }
  } catch (FileNotFoundException e) {
    System.out.println("No such file " + confPath);
    throw new RuntimeException("No config file");
  } catch (Exception e1) {
    e1.printStackTrace();
    throw new RuntimeException("Failed to read config file");
  }
  return ret;
}

代码示例来源:origin: alibaba/jstorm

public static Map loadDefinedConf(String confFile) {
  File file = new File(confFile);
  if (!file.exists()) {
    return LoadConf.findAndReadYaml(confFile, true, false);
  }
  Yaml yaml = new Yaml();
  Map ret;
  try {
    ret = (Map) yaml.load(new FileReader(file));
  } catch (FileNotFoundException e) {
    ret = null;
  }
  if (ret == null)
    ret = new HashMap();
  return new HashMap(ret);
}

代码示例来源:origin: alibaba/jstorm

private static Map loadYaml(String confPath) {
  Map ret = new HashMap<>();
  Yaml yaml = new Yaml();
  InputStream stream = null;
  try {
    stream = new FileInputStream(confPath);
    ret = (Map) yaml.load(stream);
    if (ret == null || ret.isEmpty()) {
      return null;
    }
  } catch (FileNotFoundException e) {
    throw new RuntimeException("No config file");
  } catch (Exception e1) {
    throw new RuntimeException("Failed to read config file");
  } finally {
    if (stream != null) {
      try {
        stream.close();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
  return ret;
}

代码示例来源:origin: apache/incubator-pinot

public static void main(String[] args)
   throws Exception {
  PerfBenchmarkDriverConf conf = (PerfBenchmarkDriverConf) new Yaml().load(new FileInputStream(args[0]));
  PerfBenchmarkDriver perfBenchmarkDriver = new PerfBenchmarkDriver(conf);
  perfBenchmarkDriver.run();
 }
}

代码示例来源:origin: apache/incubator-dubbo

private static <T> T parseObject(String rawConfig) {
  Constructor constructor = new Constructor(ConfiguratorConfig.class);
  TypeDescription itemDescription = new TypeDescription(ConfiguratorConfig.class);
  itemDescription.addPropertyParameters("items", ConfigItem.class);
  constructor.addTypeDescription(itemDescription);
  Yaml yaml = new Yaml(constructor);
  return yaml.load(rawConfig);
}

代码示例来源:origin: cloudfoundry/uaa

public List<UrlGroup> getUrlGroups() throws IOException {
  ClassPathResource resource = new ClassPathResource("performance-url-groups.yml");
  Yaml yaml = new Yaml();
  List<Map<String,Object>> load = (List<Map<String, Object>>) yaml.load(resource.getInputStream());
  return load.stream().map(map -> UrlGroup.from(map)).collect(Collectors.toList());
}

代码示例来源:origin: apache/incubator-dubbo

private static <T> T parseObject(String rawConfig) {
  Constructor constructor = new Constructor(ConfiguratorConfig.class);
  TypeDescription itemDescription = new TypeDescription(ConfiguratorConfig.class);
  itemDescription.addPropertyParameters("items", ConfigItem.class);
  constructor.addTypeDescription(itemDescription);
  Yaml yaml = new Yaml(constructor);
  return yaml.load(rawConfig);
}

代码示例来源:origin: cloudfoundry/uaa

public static void main(String[] args) throws Exception {
    if (args.length != 1) {
      throw new IllegalArgumentException("YAML file required");
    }
    Yaml yaml = new Yaml(new UaaConfigConstructor());
    BufferedReader br = new BufferedReader(new FileReader(args[0]));
    UaaConfiguration config = (UaaConfiguration) yaml.load(br);
    ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
    Validator validator = factory.getValidator();
    Set<ConstraintViolation<UaaConfiguration>> errors = validator.validate(config);
    System.out.println(errors);
  }
}

代码示例来源:origin: Netflix/Priam

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));
}

代码示例来源:origin: apache/storm

/**
 * Parse the TopologyLoadConf from a file in YAML format.
 * @param file the file to read from
 * @return the parsed conf
 * @throws IOException if there is an issue reading the file.
 */
public static TopologyLoadConf fromConf(File file) throws IOException {
  Yaml yaml = new Yaml(new SafeConstructor());
  Map<String, Object> yamlConf = (Map<String, Object>)yaml.load(new FileReader(file));
  return TopologyLoadConf.fromConf(yamlConf);
}

代码示例来源:origin: fabric8io/docker-maven-plugin

private Map<String,?> readKubeConfig() {
  String kubeConfig = System.getenv("KUBECONFIG");
  Reader reader = kubeConfig == null
      ? getFileReaderFromDir(new File(getHomeDir(),".kube/config"))
      : getFileReaderFromDir(new File(kubeConfig));
  if (reader != null) {
    Yaml ret = new Yaml();
    return (Map<String, ?>) ret.load(reader);
  }
  return null;
}

代码示例来源:origin: apache/incubator-dubbo

public static ConditionRouterRule parse(String rawRule) {
  Constructor constructor = new Constructor(ConditionRouterRule.class);
  Yaml yaml = new Yaml(constructor);
  ConditionRouterRule rule = yaml.load(rawRule);
  rule.setRawRule(rawRule);
  if (CollectionUtils.isEmpty(rule.getConditions())) {
    rule.setValid(false);
  }
  return rule;
}

代码示例来源:origin: apache/incubator-dubbo

public static ConditionRouterRule parse(String rawRule) {
  Constructor constructor = new Constructor(ConditionRouterRule.class);
  Yaml yaml = new Yaml(constructor);
  ConditionRouterRule rule = yaml.load(rawRule);
  rule.setRawRule(rawRule);
  if (CollectionUtils.isEmpty(rule.getConditions())) {
    rule.setValid(false);
  }
  return rule;
}

代码示例来源:origin: cloudfoundry/uaa

@Override
@SuppressWarnings("unchecked")
public void afterPropertiesSet() throws Exception {
  Assert.state(yaml != null, "Yaml document should not be null");
  Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
  try {
    logger.trace("Yaml document is\n" + yaml);
    configuration = (T) (new Yaml(constructor)).load(yaml);
    Set<ConstraintViolation<T>> errors = validator.validate(configuration);
    if (!errors.isEmpty()) {
      logger.error("YAML configuration failed validation");
      for (ConstraintViolation<?> error : errors) {
        logger.error(error.getPropertyPath() + ": " + error.getMessage());
      }
      if (exceptionIfInvalid) {
        @SuppressWarnings("rawtypes")
        ConstraintViolationException summary = new ConstraintViolationException((Set) errors);
        throw summary;
      }
    }
  } catch (YAMLException e) {
    if (exceptionIfInvalid) {
      throw e;
    }
  }
}

代码示例来源:origin: alibaba/mdrill

Yaml yaml = new Yaml();
      Map ret = (Map) yaml.load(isr);
      if (ret != null)
Yaml yaml = new Yaml();
Map ret = (Map) yaml.load(new InputStreamReader(resource
    .openStream()));
if (ret == null)

代码示例来源:origin: alibaba/jstorm

in = getConfigFileInputStream(name, canMultiple);
if (null != in) {
  Yaml yaml = new Yaml(new SafeConstructor());
  Map ret = (Map) yaml.load(new InputStreamReader(in));
  if (null != ret) {
    return new HashMap(ret);

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