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


Java CustomClassLoaderConstructor类代码示例

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


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

示例1: readConfigFile

import org.yaml.snakeyaml.constructor.CustomClassLoaderConstructor; //导入依赖的package包/类
/**
 * Read a.yaml file according to a class type.
 *
 * @param file      File path of the configuration file
 * @param classType Class type of the.yaml bean
 * @param <T>       Class T
 * @return Config file bean
 * @throws CarbonIdentityMgtConfigException Error in reading configuration file
 */
public static <T> T readConfigFile(Path file, Class<T> classType)
        throws CarbonIdentityMgtConfigException {

    if (Files.exists(file)) {
        try {
            Reader in = new InputStreamReader(Files.newInputStream(file), StandardCharsets.UTF_8);
            CustomClassLoaderConstructor constructor =
                    new CustomClassLoaderConstructor(classType.getClassLoader());
            Yaml yaml = new Yaml(constructor);
            yaml.setBeanAccess(BeanAccess.FIELD);
            return yaml.loadAs(in, classType);
        } catch (IOException e) {
            throw new CarbonIdentityMgtConfigException(String.format("Error in reading file %s", file.toString())
                    , e);
        }
    } else {
        throw new CarbonIdentityMgtConfigException(String
                .format("Configuration file %s is not available.", file.toString()));
    }
}
 
开发者ID:wso2,项目名称:carbon-identity-mgt,代码行数:30,代码来源:FileUtil.java

示例2: readConfigFiles

import org.yaml.snakeyaml.constructor.CustomClassLoaderConstructor; //导入依赖的package包/类
/**
 * Read a.yaml file according to a class type.
 *
 * @param path          folder which contain the config files
 * @param classType     Class type of the.yaml bean
 * @param fileNameRegex file name regex
 * @param <T>           Class T
 * @return Config file bean
 * @throws CarbonIdentityMgtConfigException Error in reading configuration file
 */
public static <T> List<T> readConfigFiles(Path path, Class<T> classType, String fileNameRegex)
        throws CarbonIdentityMgtConfigException {

    List<T> configEntries = new ArrayList<>();
    if (Files.exists(path)) {
        try (DirectoryStream<Path> stream = Files.newDirectoryStream(path, fileNameRegex)) {
            for (Path file : stream) {
                Reader in = new InputStreamReader(Files.newInputStream(file), StandardCharsets.UTF_8);
                CustomClassLoaderConstructor constructor =
                        new CustomClassLoaderConstructor(classType.getClassLoader());
                Yaml yaml = new Yaml(constructor);
                yaml.setBeanAccess(BeanAccess.FIELD);
                configEntries.add(yaml.loadAs(in, classType));
            }
        } catch (DirectoryIteratorException | IOException e) {
            throw new CarbonIdentityMgtConfigException(String.format("Failed to read identity connector files " +
                    "from path: %s", path.toString()), e);
        }
    }
    return configEntries;
}
 
开发者ID:wso2,项目名称:carbon-identity-mgt,代码行数:32,代码来源:FileUtil.java

示例3: writeConfigFiles

import org.yaml.snakeyaml.constructor.CustomClassLoaderConstructor; //导入依赖的package包/类
public static <T> void writeConfigFiles(Path file, Object data)
        throws IdentityRecoveryException {

    if (Files.exists(file, new LinkOption[0])) {
        try {
            CustomClassLoaderConstructor constructor =
                    new CustomClassLoaderConstructor(FileUtil.class.getClassLoader());
            Yaml yaml = new Yaml(constructor);
            yaml.setBeanAccess(BeanAccess.FIELD);
            try (Writer writer = new OutputStreamWriter(new FileOutputStream(file.toFile()),
                                                        StandardCharsets.UTF_8)) {
                yaml.dump(data, writer);
            }
        } catch (IOException e) {
            throw new IdentityRecoveryException(
                    String.format("Error in reading file %s", new Object[] { file.toString() }), e);
        }
    } else {
        throw new IdentityRecoveryException(
                String.format("Configuration file %s is not available.", new Object[] { file.toString() }));
    }
}
 
开发者ID:wso2,项目名称:carbon-identity-mgt,代码行数:23,代码来源:FileUtil.java

示例4: loadFromYaml

import org.yaml.snakeyaml.constructor.CustomClassLoaderConstructor; //导入依赖的package包/类
public Map<String, Object> loadFromYaml(){
    InputStream stream = getClass().getClassLoader().getResourceAsStream(YML_CONFIG_LOCATION);
    if(stream == null) {
        logger.warn("Configuration file not found. Empty config loaded.");
        return new HashMap<>();
    } else {
        try {
            String yamlContent = IOUtils.toString(stream, Charset.defaultCharset());
            CustomClassLoaderConstructor constr = new CustomClassLoaderConstructor(
                    Thread.currentThread().getContextClassLoader());
            Yaml yaml = new Yaml(constr);
            Map<String, Object> map = (Map<String, Object>) yaml.load(yamlContent);
            logger.info("Loaded config file");
            return map;
        } catch (IOException e) {
            throw new ServiceConfigurationException(e);
        }

    }
}
 
开发者ID:WarpOrganization,项目名称:warp,代码行数:21,代码来源:ConfigLoader.java

示例5: getConfiguration

import org.yaml.snakeyaml.constructor.CustomClassLoaderConstructor; //导入依赖的package包/类
/**
 * Get the {@code TransportsConfiguration} represented by a particular configuration file
 *
 * @param configFileLocation configuration file location
 * @return TransportsConfiguration represented by a particular configuration file
 */
public TransportsConfiguration getConfiguration(String configFileLocation) {
    TransportsConfiguration transportsConfiguration;

    File file = new File(configFileLocation);
    if (file.exists()) {
        try (Reader in = new InputStreamReader(new FileInputStream(file), StandardCharsets.ISO_8859_1)) {
            Yaml yaml = new Yaml(new CustomClassLoaderConstructor
                    (TransportsConfiguration.class, TransportsConfiguration.class.getClassLoader()));
            yaml.setBeanAccess(BeanAccess.FIELD);
            transportsConfiguration = yaml.loadAs(in, TransportsConfiguration.class);
        } catch (IOException e) {
            throw new RuntimeException(
                    "Error while loading " + configFileLocation + " configuration file", e);
        }
    } else { // return a default config
        log.warn("Netty transport configuration file not found in: " + configFileLocation +
                 " ,hence using default configuration");
        transportsConfiguration = TransportsConfiguration.getDefault();
    }

    return transportsConfiguration;
}
 
开发者ID:wso2,项目名称:carbon-transports,代码行数:29,代码来源:ConfigurationBuilder.java

示例6: getConfiguration

import org.yaml.snakeyaml.constructor.CustomClassLoaderConstructor; //导入依赖的package包/类
public static TransportsConfiguration getConfiguration(String configFileLocation) {
    TransportsConfiguration transportsConfiguration;

    File file = new File(TestUtil.class.getResource(configFileLocation).getFile());
    if (file.exists()) {
        try (Reader in = new InputStreamReader(new FileInputStream(file), StandardCharsets.ISO_8859_1)) {
            Yaml yaml = new Yaml(new CustomClassLoaderConstructor
                                         (TransportsConfiguration.class,
                                          TransportsConfiguration.class.getClassLoader()));
            yaml.setBeanAccess(BeanAccess.FIELD);
            transportsConfiguration = yaml.loadAs(in, TransportsConfiguration.class);
        } catch (IOException e) {
            throw new RuntimeException(
                    "Error while loading " + configFileLocation + " configuration file", e);
        }
    } else { // return a default config
        log.warn("Netty transport configuration file not found in: " + configFileLocation +
                         " ,hence using default configuration");
        transportsConfiguration = TransportsConfiguration.getDefault();
    }

    return transportsConfiguration;
}
 
开发者ID:wso2,项目名称:carbon-transports,代码行数:24,代码来源:TestUtil.java

示例7: configureFromInputStream

import org.yaml.snakeyaml.constructor.CustomClassLoaderConstructor; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected void configureFromInputStream(InputStream is) {
    Yaml yaml = new Yaml(new CustomClassLoaderConstructor(getClass().getClassLoader()));
    Map<String, Object> document = (Map<String, Object>) yaml.load(is);
    if (document == null || !document.containsKey(HANDLER_MAPPINGS_KEY)) {
        throw new IllegalArgumentException(String.format("Expected yaml document with key: %s",
                HANDLER_MAPPINGS_KEY));
    } else {
        Map<String, SaltReturnHandler> handlers = (Map<String, SaltReturnHandler>) document
                .get(HANDLER_MAPPINGS_KEY);
        for (Map.Entry<String, SaltReturnHandler> entry : handlers.entrySet()) {
            if (handlerMap.containsKey(entry.getKey())) {
                throw new IllegalStateException(String.format(
                        "Already received a salt return handler configuration entry for %s", entry.getKey()));
            }
            handlerMap.put(entry.getKey(), entry.getValue());
        }
    }
}
 
开发者ID:rundeck-plugins,项目名称:salt-step,代码行数:20,代码来源:SaltReturnHandlerRegistry.java

示例8: readConfigFile

import org.yaml.snakeyaml.constructor.CustomClassLoaderConstructor; //导入依赖的package包/类
public static <T> T readConfigFile(Path file, Class<T> classType) throws IdentityRecoveryException {

        try (InputStreamReader inputStreamReader =
                     new InputStreamReader(Files.newInputStream(file), StandardCharsets.UTF_8)) {
            CustomClassLoaderConstructor constructor =
                    new CustomClassLoaderConstructor(FileUtil.class.getClassLoader());
            Yaml yaml = new Yaml(constructor);
            yaml.setBeanAccess(BeanAccess.FIELD);
            return yaml.loadAs(inputStreamReader, classType);
        } catch (IOException e) {
            throw new IdentityRecoveryException(
                    String.format("Error in reading file %s", file.toString()), e);
        }
    }
 
开发者ID:wso2,项目名称:carbon-identity-mgt,代码行数:15,代码来源:FileUtil.java

示例9: load

import org.yaml.snakeyaml.constructor.CustomClassLoaderConstructor; //导入依赖的package包/类
public static Info load(URL directory) {
  CustomClassLoaderConstructor constr = 
          new CustomClassLoaderConstructor(Info.class.getClassLoader());
  Yaml yaml = new Yaml(constr);
  Object obj;
  URL infoFile = newURL(directory,FILENAME_INFO);
  try (InputStream is = infoFile.openStream()) {
    obj = yaml.loadAs(new InputStreamReader(is,"UTF-8"),Info.class);
  } catch (Exception ex) {
    throw new GateRuntimeException("Could not load info file "+infoFile,ex);
  }    
  Info info = (Info)obj;    
  return info;
}
 
开发者ID:GateNLP,项目名称:gateplugin-LearningFramework,代码行数:15,代码来源:Info.java

示例10: initialValue

import org.yaml.snakeyaml.constructor.CustomClassLoaderConstructor; //导入依赖的package包/类
protected Yaml initialValue() {
    DumperOptions options = new DumperOptions();
    options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
    CustomClassLoaderConstructor constructor = new CustomClassLoaderConstructor(getClass().getClassLoader());
    PropertyUtils propertyUtils = constructor.getPropertyUtils();
    propertyUtils.setSkipMissingProperties(true);
    constructor.setPropertyUtils(propertyUtils);
    return new Yaml(constructor, new Representer(), options);
}
 
开发者ID:CodeCrafter47,项目名称:FreeBungeeChat,代码行数:10,代码来源:CustomClassLoaderYamlConfiguration.java

示例11: loadYaml

import org.yaml.snakeyaml.constructor.CustomClassLoaderConstructor; //导入依赖的package包/类
/**
 * Load and parse a plain YAML file and returns the corresponding Java Map.
 * The YAML parser used is SnakeYAML (http://code.google.com/p/snakeyaml/)
 * @param name Name of a YAML file somewhere in the classpath (or conf/)me
 * @param clazz the expected class
 * @return Object representing the YAML data
 */
@SuppressWarnings("unchecked")
public static <T> T loadYaml(String name, Class<T> clazz) {
    Yaml yaml = new Yaml(new CustomClassLoaderConstructor(clazz, Play.classloader));
    yaml.setBeanAccess(BeanAccess.FIELD);
    return (T)loadYaml(name, yaml);
}
 
开发者ID:eBay,项目名称:restcommander,代码行数:14,代码来源:Fixtures.java

示例12: loadAs

import org.yaml.snakeyaml.constructor.CustomClassLoaderConstructor; //导入依赖的package包/类
/**
 * Parses the configuration file and produces an object of the specified
 * class.
 * 
 * @param <T>
 *            Class of the object specified by the {@code clazz} parameter
 * @param clazz
 *            class of the object to be created
 * @return the object created from the configuration file
 * @throws IOException
 *             if an I/O error occurs opening the configuration file
 */
public <T> T loadAs(Class<T> clazz) throws IOException {
	CustomClassLoaderConstructor constr = new CustomClassLoaderConstructor(
			clazz.getClassLoader());
	Yaml yaml = new Yaml(constr);
	try (BufferedReader r = Files.newBufferedReader(path)) {
		return yaml.loadAs(r, clazz);
	}
}
 
开发者ID:sfera-labs,项目名称:sfera,代码行数:21,代码来源:Configuration.java


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