当前位置: 首页>>代码示例>>Java>>正文


Java Yaml类代码示例

本文整理汇总了Java中com.fasterxml.jackson.dataformat.yaml.snakeyaml.Yaml的典型用法代码示例。如果您正苦于以下问题:Java Yaml类的具体用法?Java Yaml怎么用?Java Yaml使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Yaml类属于com.fasterxml.jackson.dataformat.yaml.snakeyaml包,在下文中一共展示了Yaml类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: readConfiguration

import com.fasterxml.jackson.dataformat.yaml.snakeyaml.Yaml; //导入依赖的package包/类
private void readConfiguration() throws SnoopEEConfigurationException {

        Map<String, Object> snoopConfig = Collections.EMPTY_MAP;
        try {
            Yaml yaml = new Yaml();
            Map<String, Object> props = (Map<String, Object>) yaml.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("/snoopee.yml"));
            snoopConfig = (Map<String, Object>) props.get("snoopee");

        } catch (YAMLException e) {
            LOGGER.config(() -> "No configuration file. Using env properties.");
        }

        applicationConfig.setServiceName(SnoopEEExtensionHelper.getServiceName());
        final String host = readProperty("host", snoopConfig);
        final String port = readProperty("port", snoopConfig);
        applicationConfig.setServiceHome(host + ":" + port + "/");
        applicationConfig.setServiceRoot(readProperty("serviceRoot", snoopConfig));

        LOGGER.config(() -> "application config: " + applicationConfig.toJSON());

        serviceUrl = "ws://" + readProperty("snoopeeService", snoopConfig);
    }
 
开发者ID:ivargrimstad,项目名称:snoopee,代码行数:23,代码来源:SnoopEERegistrationClient.java

示例2: init

import com.fasterxml.jackson.dataformat.yaml.snakeyaml.Yaml; //导入依赖的package包/类
/**
 * Initializes the producer with the SnoopEE configuration properties.
 */
@PostConstruct
private void init() {

    try {
        Yaml yaml = new Yaml();
        Map<String, Object> props = (Map<String, Object>) yaml.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("/snoopee.yml"));

        snoopeeConfig = (Map<String, Object>) props.get("snoopee");

        if (!SnoopEEExtensionHelper.isSnoopEnabled()) {
            SnoopEEExtensionHelper.setServiceName(readProperty("serviceName", snoopeeConfig));
        }

    } catch (YAMLException e) {
        LOGGER.config(() -> "No configuration file. Using env properties.");
    }
}
 
开发者ID:ivargrimstad,项目名称:snoopee,代码行数:21,代码来源:SnoopEEProducer.java

示例3: readConfiguration

import com.fasterxml.jackson.dataformat.yaml.snakeyaml.Yaml; //导入依赖的package包/类
private void readConfiguration() throws SnoopEEConfigurationException {

        Map<String, Object> snoopConfig = Collections.EMPTY_MAP;
        try {
            Yaml yaml = new Yaml();
            Map<String, Object> props = (Map<String, Object>) yaml.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("/snoopee.yml"));

            snoopConfig = (Map<String, Object>) props.get("snoopee");

        } catch (YAMLException e) {
            LOGGER.config(() -> "No configuration file. Using env properties.");
        }

        applicationConfig.setServiceName(SnoopEEExtensionHelper.getServiceName());
        final String host = readProperty("host", snoopConfig);
        final String port = readProperty("port", snoopConfig);
        applicationConfig.setServiceHome(host + ":" + port + "/");
        applicationConfig.setServiceRoot(readProperty("serviceRoot", snoopConfig));

        LOGGER.config(() -> "application config: " + applicationConfig.toJSON());

        serviceUrl = "http://" + readProperty("snoopeeService", snoopConfig);
    }
 
开发者ID:ivargrimstad,项目名称:snoopee,代码行数:24,代码来源:SnoopEERegistrationClient.java

示例4: parseFile

import com.fasterxml.jackson.dataformat.yaml.snakeyaml.Yaml; //导入依赖的package包/类
/**
 * Load a file from GCS or local and parse from json or yaml.
 *
 * @param <T>
 */
@SuppressWarnings("unchecked")
public static <T> T parseFile(String path, Class<T> c) throws IOException {
  LOG.info("Parse file from path: " + path + " for class " + c);

  String text = readAll(path);

  // Ridiculous hack: direct parsing into a real Java object fails with
  // SnakeYaml, Gson and Jackson due to mysterious type incompatibility :(
  Map<String, Object> map;
  if (path.endsWith("yaml") || path.endsWith("yml")) {
    map = (Map<String, Object>) new Yaml().load(text);

  } else {
    map =
        (Map<String, Object>)
            new GsonBuilder()
                .setLenient()
                .create()
                .fromJson(text, new TypeToken<Map<String, Object>>() {}.getType());
  }

  String s = StringUtils.toJson(map);
  return StringUtils.fromJson(s, c);
}
 
开发者ID:googlegenomics,项目名称:dockerflow,代码行数:30,代码来源:FileUtils.java

示例5: CompileTimeConfiguration

import com.fasterxml.jackson.dataformat.yaml.snakeyaml.Yaml; //导入依赖的package包/类
public CompileTimeConfiguration(Path file) throws IOException {
    configurationFile = Paths.get(System.getProperty("user.dir")).resolve(file);
    Map yaml = getElement(new Yaml().load(Files.toString(configurationFile.toFile(), Charset.forName("UTF8"))),
                          Map.class);

    name = yaml.get("name").toString();
    version = new Version(Integer.parseInt(yaml.get("version").toString()), 0);
    basePath = Paths.get(yaml.get("path").toString());
    backupPath = Paths.get(getElement(yaml, "backupPath", String.class, DEFAULT_BACKUP_PATH));

    instrumentationConfiguration = new InstrumentationConfiguration(this, getChild(yaml, "instrumentation", Map.class));
    optimizationConfiguration = new OptimizationConfiguration(this, getChild(yaml, "optimization", Map.class));
    datapipeConfiguration = new DataPipeConfiguration(this, getChild(yaml, "datapipe", Map.class));
    importTask = new ImportTaskImpl(this);
    exportTask = new ExportTaskImpl(this);
}
 
开发者ID:uwdb,项目名称:pipegen,代码行数:17,代码来源:CompileTimeConfiguration.java

示例6: readConfiguration

import com.fasterxml.jackson.dataformat.yaml.snakeyaml.Yaml; //导入依赖的package包/类
private void readConfiguration() throws SnoopConfigurationException {

        Map<String, Object> snoopConfig = Collections.EMPTY_MAP;
        try {
            Yaml yaml = new Yaml();
            Map<String, Object> props = (Map<String, Object>) yaml.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("/snoop.yml"));

            snoopConfig = (Map<String, Object>) props.get("snoop");

        } catch (YAMLException e) {
            LOGGER.config(() -> "No configuration file. Using env properties.");
        }

        applicationConfig.setServiceName(SnoopExtensionHelper.getServiceName());
        final String host = readProperty("host", snoopConfig);
        final String port = readProperty("port", snoopConfig);
        applicationConfig.setServiceHome(host + ":" + port + "/");
        applicationConfig.setServiceRoot(readProperty("serviceRoot", snoopConfig));

        LOGGER.config(() -> "application config: " + applicationConfig.toJSON());

        serviceUrl = "ws://" + readProperty("snoopService", snoopConfig);
    }
 
开发者ID:ivargrimstad,项目名称:snoop,代码行数:24,代码来源:SnoopRegistrationClient.java

示例7: readProperties

import com.fasterxml.jackson.dataformat.yaml.snakeyaml.Yaml; //导入依赖的package包/类
private void readProperties() {
   Yaml yaml = new Yaml();
   Map<String, Object> props = (Map<String, Object>) yaml.load(this.getClass().getResourceAsStream("/application.yml"));

   Map<String, String> snoopConfig = (Map<String, String>) props.get("snoop");

   applicationName = snoopConfig.get("applicationName");
   applicationHome = snoopConfig.get("applicationHome");

   LOGGER.config(() -> "application name: " + applicationName);
   
   Map<String, Object> eurekaProps = (Map<String, Object>) props.get("eureka");
   Map<String, Object> eurekaClientProps = (Map<String, Object>) eurekaProps.get("client");
   Map<String, String> eurekaServiceProps = (Map<String, String>) eurekaClientProps.get("serviceUrl");

   serviceUrl = eurekaServiceProps.get("deafaultZone") != null ? snoopConfig.get("defaultZone") : DEFAULT_SERVICE_URI;
}
 
开发者ID:ivargrimstad,项目名称:snoop,代码行数:18,代码来源:EurekaClient.java

示例8: parseConfig

import com.fasterxml.jackson.dataformat.yaml.snakeyaml.Yaml; //导入依赖的package包/类
private static Config parseConfig(String[] args){
    if(args != null && args.length > 0) {
        String config = args[0];
        File configFile = new File(config);
        Yaml yaml = new Yaml();

        if (configFile.exists()) {

            try {
                return yaml.loadAs(FileUtils.openInputStream(configFile), Config.class);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    return loadDefaultConfig();
}
 
开发者ID:52inc,项目名称:lol52,代码行数:19,代码来源:App.java

示例9: makeYaml

import com.fasterxml.jackson.dataformat.yaml.snakeyaml.Yaml; //导入依赖的package包/类
private static String makeYaml(List<Map.Entry<String, Map<String, Object>>> keysAndComponents) {
    Map<String, Object> yamlMap;
    StringWriter yamlStr = new StringWriter();
    yamlMap = new LinkedHashMap<>();
    yamlMap.put(StormTopologyLayoutConstants.YAML_KEY_NAME, "topo1");

    for (Map.Entry<String, Map<String, Object>> entry: keysAndComponents) {
        addComponentToCollection(yamlMap, entry.getValue(), entry.getKey());
    }

    DumperOptions options = new DumperOptions();
    options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
    options.setSplitLines(false);
    Yaml yaml = new Yaml (options);
    yaml.dump(yamlMap, yamlStr);
    return yamlStr.toString();
}
 
开发者ID:hortonworks,项目名称:streamline,代码行数:18,代码来源:SLRealtimeJoinBoltFluxComponentTest.java

示例10: buildParams

import com.fasterxml.jackson.dataformat.yaml.snakeyaml.Yaml; //导入依赖的package包/类
private Object[] buildParams(Object[] params,
        ServiceSpecification spec, Map<String, Object> serviceConfig) {

    // Add existing params
    List<Object> paramList = new ArrayList<Object>();
    for(int i = 0; i < params.length; ++i)
        paramList.add(params[i]);
    
    // Add any dependency services
    Class<?>[] dependencies = spec.metadata.dependencies();
    for(int i = 0; i < dependencies.length; ++i)
        paramList.add(getService(dependencies[i]));

    // If the service requires a configuration, add it
    Class<?> configClass = spec.metadata.configClass();
    if(configClass != Void.class){
        Yaml yaml = new Yaml();           
        String configString = yaml.dump(serviceConfig);
        Object configObject = yaml.loadAs(configString, configClass);
        paramList.add(configObject);
    }
    
    return paramList.toArray();
}
 
开发者ID:mongodb-labs,项目名称:hvdf,代码行数:25,代码来源:ServiceFactory.java

示例11: deserializeIntoJson

import com.fasterxml.jackson.dataformat.yaml.snakeyaml.Yaml; //导入依赖的package包/类
/**
 * Get a common string as JSON to be parsed
 *
 * @param filePath with the file path
 * @return a common string as JSON to be parsed
 * @throws APIRestGeneratorException with an occurred exception
 */
public static JsonNode deserializeIntoJson(final String filePath) throws APIRestGeneratorException
{
    JsonNode jsonNode = null;

    final String fileExtension = ParserUtil.validateExtension(filePath);
    final String fileContent = ParserUtil.readFileContent(filePath);

    try
    {
        if (fileExtension.equals(ConstantsCommon.EXTENSION_YAML) || fileExtension.equals(ConstantsCommon.EXTENSION_YAML_OTHER))
        {
            final Yaml yaml = new Yaml();
            jsonNode = (JsonNode) Json.mapper().convertValue(yaml.load(fileContent), JsonNode.class);
        }
        else
        {
            jsonNode = Json.mapper().readTree(fileContent);
        }
    }
    catch (IOException ioException)
    {
        final String errorString = "IOException when reading the file: " + ioException;

        ParserUtil.LOGGER.error(errorString, ioException);
        throw new APIRestGeneratorException(errorString, ioException);
    }

    return jsonNode;
}
 
开发者ID:BBVA-CIB,项目名称:APIRestGenerator,代码行数:37,代码来源:ParserUtil.java

示例12: init

import com.fasterxml.jackson.dataformat.yaml.snakeyaml.Yaml; //导入依赖的package包/类
/**
 * Initializes the producer with the Snoop configuration properties.
 */
@PostConstruct
private void init() {

    try {
        Yaml yaml = new Yaml();
        Map<String, Object> props = (Map<String, Object>) yaml.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("/snoop.yml"));

        snoopConfig = (Map<String, Object>) props.get("snoop");

    } catch (YAMLException e) {
        LOGGER.config(() -> "No configuration file. Using env properties.");
    }
}
 
开发者ID:ivargrimstad,项目名称:snoop,代码行数:17,代码来源:SnoopProducer.java

示例13: loadDefaultConfig

import com.fasterxml.jackson.dataformat.yaml.snakeyaml.Yaml; //导入依赖的package包/类
private static Config loadDefaultConfig(){
    String fullPath = "config/default_config.yml";
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    InputStream is = classLoader.getResourceAsStream(fullPath);
    Yaml yaml = new Yaml();
    return yaml.loadAs(is, Config.class);
}
 
开发者ID:52inc,项目名称:lol52,代码行数:8,代码来源:App.java

示例14: toYamlString

import com.fasterxml.jackson.dataformat.yaml.snakeyaml.Yaml; //导入依赖的package包/类
public String toYamlString(Map<String, Object> yamlMap) {
    StringWriter yamlStr = new StringWriter();
    DumperOptions options = new DumperOptions();
    options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
    options.setSplitLines(true);
    options.setPrettyFlow(true);
    Yaml yaml = new Yaml(options);
    yaml.dump(yamlMap, yamlStr);

    return yamlStr.toString();
}
 
开发者ID:hortonworks,项目名称:streamline,代码行数:12,代码来源:FluxBoltGenerator.java

示例15: toYaml

import com.fasterxml.jackson.dataformat.yaml.snakeyaml.Yaml; //导入依赖的package包/类
public static String toYaml(Object o) throws IOException {
  // Round trip to json to suppress empty collections and null values
  String json = toJson(o);
  Object generic = fromJson(json, Object.class);
  return new Yaml().dump(generic);
}
 
开发者ID:googlegenomics,项目名称:dockerflow,代码行数:7,代码来源:StringUtils.java


注:本文中的com.fasterxml.jackson.dataformat.yaml.snakeyaml.Yaml类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。