本文整理汇总了Java中org.yaml.snakeyaml.Yaml.loadAs方法的典型用法代码示例。如果您正苦于以下问题:Java Yaml.loadAs方法的具体用法?Java Yaml.loadAs怎么用?Java Yaml.loadAs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.yaml.snakeyaml.Yaml
的用法示例。
在下文中一共展示了Yaml.loadAs方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadServerFromConfigFile
import org.yaml.snakeyaml.Yaml; //导入方法依赖的package包/类
/**
* 加载配置文件
*/
private void loadServerFromConfigFile() {
InputStream inputStream = parseYamlFile(CONFIG_FILE_NAME, true);
Yaml yaml = new Yaml();
YamlServerConfig config = yaml.loadAs(inputStream, YamlServerConfig.class);
List<YamlServerList> servers = config.servers;
for (YamlServerList server : servers) {
for (ServerInstance instance : server.getInstances()) {
instance.setServiceName(server.getServiceName());
instance.ready();
}
instanceMap.put(server.getServiceName(), server.getInstances());
}
log.info("成功加载server的配置文件:{},Server:{}", CONFIG_FILE_NAME, instanceMap);
}
示例2: initUserSettingsProducer
import org.yaml.snakeyaml.Yaml; //导入方法依赖的package包/类
@PostConstruct
private void initUserSettingsProducer() {
try {
File coreYml = new File(BiliomiContainer.getParameters().getConfigurationDir(), "core.yml");
Yaml yamlInstance = new Yaml(new Constructor(YamlCoreSettings.class));
yamlCoreSettings = yamlInstance.loadAs(new FileInputStream(coreYml), YamlCoreSettings.class);
String updateMode = yamlCoreSettings.getBiliomi().getCore().getUpdateMode();
// Somehow Yaml thinks "off" means "false"
if (StringUtils.isEmpty(updateMode)) {
this.updateMode = UpdateModeType.OFF;
} else {
this.updateMode = EnumUtils.toEnum(updateMode, UpdateModeType.class);
}
} catch (FileNotFoundException e) {
this.yamlCoreSettings = new YamlCoreSettings();
ObjectGraphs.initializeObjectGraph(this.yamlCoreSettings);
this.updateMode = UpdateModeType.INSTALL;
this.yamlCoreSettings.getBiliomi().getCore().setUpdateMode(this.updateMode.toString());
}
}
示例3: main
import org.yaml.snakeyaml.Yaml; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
if (args.length < 1) {
System.out.println("Usage: <file.yml> [iffnit]");
return;
}
Yaml yaml = new Yaml();
try (InputStream in = Files.newInputStream(Paths.get(args[0]))) {
Configuration config = yaml.loadAs(in, Configuration.class);
System.out.println(config.toString());
}
if (args.length > 1 && args[1].equals("init")) {
ReplicaInit replicaInit = new ReplicaInit();
replicaInit.start();
} else if (args.length > 1 && !args[1].equals("init")) {
System.out.println("Usage: <file.yml> [init]");
} else {
ReplicaEvent replicaEvent = new ReplicaEvent();
replicaEvent.start();
}
}
示例4: main
import org.yaml.snakeyaml.Yaml; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
if (args.length < 1) {
System.out.println("Usage: <file.yml>");
return;
}
Yaml yaml = new Yaml();
try (InputStream in = Files.newInputStream(Paths.get(args[0]))) {
Configuration config = yaml.loadAs(in, Configuration.class);
System.out.println(config.toString());
}
Connection c = Connect.open();
Downloader downloader = new Downloader();
downloader.read();
c.commit();
c.close();
}
示例5: get
import org.yaml.snakeyaml.Yaml; //导入方法依赖的package包/类
public static MediaToolConfig get(Path config)
{
try {
Yaml yaml = new Yaml();
try (InputStream in = Files.newInputStream(config))
{
MediaToolConfig mediaConfig = yaml.loadAs(in, MediaToolConfig.class);
if (logger.isInfoEnabled())
logger.info("{}", mediaConfig.toString());
return mediaConfig;
}
} catch (IOException oie) {
logger.error("{}", oie.getMessage(), oie);
}
return null;
}
示例6: clientThread
import org.yaml.snakeyaml.Yaml; //导入方法依赖的package包/类
public clientThread(Socket clientSocket, clientThread[] threads, MultiThreadChatServerSync mtcss) {
this.clientSocket = clientSocket;
this.mtcss = mtcss;
if (config == null) {
Yaml yaml = new Yaml();
InputStream in = ClassLoader.getSystemResourceAsStream("config.yml");
config = yaml.loadAs(in, ConfigConfiguration.class);
}
try {
this.clientSocket.setSoTimeout(config.getMaxTimeOut() * 1000);
} catch (SocketException e) {
e.printStackTrace();
}
service = new ToneAnalyzer("2017-09-21", config.getWatsonUser(), config.getWatsonPass());
}
示例7: parseContent
import org.yaml.snakeyaml.Yaml; //导入方法依赖的package包/类
private void parseContent(String content) {
switch (this.type) {
case Config.PROPERTIES:
this.parseProperties(content);
break;
case Config.JSON:
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
this.config = new ConfigSection(gson.fromJson(content, new TypeToken<LinkedHashMap<String, Object>>() {
}.getType()));
break;
case Config.YAML:
DumperOptions dumperOptions = new DumperOptions();
dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
Yaml yaml = new Yaml(dumperOptions);
this.config = new ConfigSection(yaml.loadAs(content, LinkedHashMap.class));
if (this.config == null) {
this.config = new ConfigSection();
}
break;
// case Config.SERIALIZED
case Config.ENUM:
this.parseList(content);
break;
default:
this.correct = false;
}
}
示例8: loadConfig
import org.yaml.snakeyaml.Yaml; //导入方法依赖的package包/类
private static InjectorConfig loadConfig() {
Optional<InjectorConfig> remoteConfig = tryRemoteConfig();
if (remoteConfig.isPresent()) return remoteConfig.get();
try (Reader reader = new InputStreamReader(lookupConfig(), StandardCharsets.UTF_8)) {
Yaml yaml = new Yaml();
return yaml.loadAs(reader, InjectorConfig.class);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
示例9: main
import org.yaml.snakeyaml.Yaml; //导入方法依赖的package包/类
public static void main(String args[]) {
// The default port number.
int portNumber = 2222;
if (args.length < 1) {
System.out.println("Usage: java MultiThreadChatServerSync <portNumber>\n"
+ "Now using port number=" + portNumber);
} else {
portNumber = Integer.valueOf(args[0]).intValue();
}
Yaml yaml = new Yaml();
InputStream in = ClassLoader.getSystemResourceAsStream("config.yml");
config = yaml.loadAs(in, ConfigConfiguration.class);
maxClientsCount = config.getMaxUserCount();
threads = new clientThread[maxClientsCount];
gson = new Gson();
/*
* Open a server socket on the portNumber (default 2222). Note that we can
* not choose a port less than 1023 if we are not privileged users (root).
*/
try {
serverSocket = new ServerSocket(portNumber);
} catch (IOException e) {
System.out.println(e);
}
/*
* Create a client socket for each connection and pass it to a new client
* thread.
*/
MultiThreadChatServerSync mtcss = new MultiThreadChatServerSync();
mtcss.syncThreads();
}
示例10: loadInner
import org.yaml.snakeyaml.Yaml; //导入方法依赖的package包/类
@Override
protected synchronized Map<String, ApiConfig> loadInner(Yaml yaml, InputStream is) throws ConfigurationException {
Map<String, ?> flesh = yaml.loadAs(is, Map.class);
Map<String, ApiConfig> confs = new LinkedHashMap<>();
for (Map.Entry<String, ?> entry : flesh.entrySet()) {
String apiName = entry.getKey();
Object raw = entry.getValue();
ApiConfig conf = createConfig(apiName, raw);
confs.put(apiName, conf);
}
return confs;
}
示例11: init
import org.yaml.snakeyaml.Yaml; //导入方法依赖的package包/类
@PostConstruct
public void init() {
try {
Yaml yaml = new Yaml();
InputStream inputStream = this.getClass().getResourceAsStream(MENU_CONFIG_FILE_PATH);
menu = yaml.loadAs(inputStream, Menu.class);
}
catch (Exception e) {
LOG.error(e.getMessage(), e);
}
}
示例12: init
import org.yaml.snakeyaml.Yaml; //导入方法依赖的package包/类
@PostConstruct
public void init() {
try {
Constructor constructor = new Constructor(VariableConfig.class);
TypeDescription variableConfigTypeDescription = new TypeDescription(VariableConfig.class);
variableConfigTypeDescription.putListPropertyType(PROPERTY_VARIABLE_GROUPS, VariableGroup.class);
constructor.addTypeDescription(variableConfigTypeDescription);
TypeDescription variableGroupTypeDescription = new TypeDescription(VariableGroup.class);
variableGroupTypeDescription.putListPropertyType(PROPERTY_VARIABLES, Variable.class);
constructor.addTypeDescription(variableGroupTypeDescription);
Yaml yaml = new Yaml(constructor);
File terraformFolder = resourceService.getClasspathResource(Constants.FOLDER_TERRAFORM);
if (!terraformFolder.isFile()) {
File[] providerFolderArray = terraformFolder.listFiles();
for (File providerFolder : providerFolderArray) {
File variableFile = new File(new URI(providerFolder.toURI() + File.separator + FILE_VARIABLES_YML));
if (variableFile.exists()) {
VariableConfig variableConfig = yaml.loadAs(new FileInputStream(variableFile), VariableConfig.class);
List<VariableGroup> variableGroupList = variableConfig.getVariableGroups();
providerDefaults.put(providerFolder.getName(), variableGroupList);
}
}
}
}
catch (Exception e) {
LOG.error(e.getMessage(), e);
}
}
示例13: ConfigService
import org.yaml.snakeyaml.Yaml; //导入方法依赖的package包/类
public ConfigService(String configPath, Class<T> constructorClass) {
T loadedConfig = null;
File file = new File(BiliomiContainer.getParameters().getConfigurationDir(), configPath);
Yaml yaml = new Yaml(new Constructor(constructorClass));
try {
loadedConfig = yaml.loadAs(new FileInputStream(file), constructorClass);
} catch (FileNotFoundException e) {
LogManager.getLogger(getClass().getName()).error("Failed loading module configuration from " + file.getAbsolutePath());
}
this.config = loadedConfig;
}
示例14: createFromYml
import org.yaml.snakeyaml.Yaml; //导入方法依赖的package包/类
public ArkNetwork createFromYml(String configFilename){
Yaml yaml = new Yaml();
InputStream fileInputStream = ResourceUtils.getInputStream(configFilename);
ArkNetworkSettings arkNetworkSettings = yaml.loadAs(fileInputStream, ArkNetworkSettings.class);
return new ArkNetwork(
arkNetworkSettings.getScheme(),
arkNetworkSettings.getPeers(),
arkNetworkSettings.getNetHash(),
arkNetworkSettings.getPort(),
arkNetworkSettings.getVersion()
);
}
示例15: load
import org.yaml.snakeyaml.Yaml; //导入方法依赖的package包/类
public static GUIConfig load(File f) throws IOException {
Yaml y = new Yaml();
GUIConfig c = y.loadAs(Files.toString(f, StandardCharsets.UTF_8), GUIConfig.class);
c.dbNames = DataStore.getDbNames();
return c;
}