本文整理汇总了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()));
}
}
示例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;
}
示例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() }));
}
}
示例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);
}
}
}
示例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;
}
示例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;
}
示例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());
}
}
}
示例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);
}
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
}