當前位置: 首頁>>代碼示例>>Java>>正文


Java SafeConstructor類代碼示例

本文整理匯總了Java中org.yaml.snakeyaml.constructor.SafeConstructor的典型用法代碼示例。如果您正苦於以下問題:Java SafeConstructor類的具體用法?Java SafeConstructor怎麽用?Java SafeConstructor使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


SafeConstructor類屬於org.yaml.snakeyaml.constructor包,在下文中一共展示了SafeConstructor類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initialize

import org.yaml.snakeyaml.constructor.SafeConstructor; //導入依賴的package包/類
private void initialize(InputStream regexYaml) {
  Yaml yaml = new Yaml(new SafeConstructor());
  Map<String,List> regexConfig = (Map<String,List>) yaml.load(regexYaml);

  List<Map> uaParserConfigs = regexConfig.get("user_agent_parsers");
  if (uaParserConfigs == null) {
    throw new IllegalArgumentException("user_agent_parsers is missing from yaml");
  }
  uaParser = UserAgentParser.fromList(uaParserConfigs);

  List<Map> osParserConfigs = regexConfig.get("os_parsers");
  if (osParserConfigs == null) {
    throw new IllegalArgumentException("os_parsers is missing from yaml");
  }
  osParser = OSParser.fromList(osParserConfigs);

  List<Map> deviceParserConfigs = regexConfig.get("device_parsers");
  if (deviceParserConfigs == null) {
    throw new IllegalArgumentException("device_parsers is missing from yaml");
  }
  deviceParser = DeviceParser.fromList(deviceParserConfigs);
}
 
開發者ID:duchien85,項目名稱:netty-cookbook,代碼行數:23,代碼來源:Parser.java

示例2: checkQuotes

import org.yaml.snakeyaml.constructor.SafeConstructor; //導入依賴的package包/類
private void checkQuotes(boolean isBlock, String expectation) {
    DumperOptions options = new DumperOptions();
    options.setIndent(4);
    if (isBlock) {
        options.setDefaultFlowStyle(FlowStyle.BLOCK);
    }
    Representer representer = new Representer();

    Yaml yaml = new Yaml(new SafeConstructor(), representer, options);

    LinkedHashMap<String, Object> lvl1 = new LinkedHashMap<String, Object>();
    lvl1.put("steak:cow", "11");
    LinkedHashMap<String, Object> root = new LinkedHashMap<String, Object>();
    root.put("cows", lvl1);
    String output = yaml.dump(root);
    assertEquals(expectation + "\n", output);

    // parse the value back
    @SuppressWarnings("unchecked")
    Map<String, Object> cows = (Map<String, Object>) yaml.load(output);
    @SuppressWarnings("unchecked")
    Map<String, String> cow = (Map<String, String>) cows.get("cows");
    assertEquals("11", cow.get("steak:cow"));
}
 
開發者ID:bmoliveira,項目名稱:snake-yaml,代碼行數:25,代碼來源:SingleQuoteTest.java

示例3: testListSafeConstructor

import org.yaml.snakeyaml.constructor.SafeConstructor; //導入依賴的package包/類
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testListSafeConstructor() {
    List value = new ArrayList();
    value.add(value);
    value.add("test");
    value.add(new Integer(1));

    Yaml yaml = new Yaml(new SafeConstructor());
    String output1 = yaml.dump(value);
    assertEquals("&id001\n- *id001\n- test\n- 1\n", output1);
    List value2 = (List) yaml.load(output1);
    assertEquals(3, value2.size());
    assertEquals(value.size(), value2.size());
    assertSame(value2, value2.get(0));
    // we expect self-reference as 1st element of the list
    // let's remove self-reference and check other "simple" members of the
    // list. otherwise assertEquals will lead us to StackOverflow
    value.remove(0);
    value2.remove(0);
    assertEquals(value, value2);
}
 
開發者ID:bmoliveira,項目名稱:snake-yaml,代碼行數:22,代碼來源:PyRecursiveTest.java

示例4: readConfigFile

import org.yaml.snakeyaml.constructor.SafeConstructor; //導入依賴的package包/類
private static Map readConfigFile(String filename) throws IOException {
    Map ret;
    Yaml yaml = new Yaml(new SafeConstructor());
    InputStream inputStream = new FileInputStream(new File(filename));

    try {
        ret = (Map)yaml.load(inputStream);
    } finally {
        inputStream.close();
    }

    if(ret == null) {
        ret = new HashMap();
    }

    return new HashMap(ret);
}
 
開發者ID:skalmadka,項目名稱:web-crawler,代碼行數:18,代碼來源:WebCrawlerTopology.java

示例5: readConfigFile

import org.yaml.snakeyaml.constructor.SafeConstructor; //導入依賴的package包/類
@SuppressWarnings("rawtypes")
public static Map readConfigFile(String file, boolean mustExist) {
  Yaml yaml = new Yaml(new SafeConstructor());
  Map ret = null;
  InputStream input = IOUtils.getInputStream(file);
  if (input != null) {
    ret = (Map) yaml.load(new InputStreamReader(input));
    LOG.info("Loaded " + file);
    try {
      input.close();
    } catch (IOException e) {
      LOG.error("IOException: " + e.getMessage());
    }
  } else if (mustExist) {
    LOG.error("Config file " + file + " was not found!");
  }
  if ((ret == null) && (mustExist)) {
    throw new RuntimeException("Config file " + file + " was not found!");
  }
  return ret;
}
 
開發者ID:millecker,項目名稱:senti-storm,代碼行數:22,代碼來源:Configuration.java

示例6: initialize

import org.yaml.snakeyaml.constructor.SafeConstructor; //導入依賴的package包/類
private void initialize(InputStream regexYaml) {
  Yaml yaml = new Yaml(new SafeConstructor());
  @SuppressWarnings("unchecked")
  Map<String,List<Map<String,String>>> regexConfig = (Map<String,List<Map<String,String>>>) yaml.load(regexYaml);

  List<Map<String,String>> uaParserConfigs = regexConfig.get("user_agent_parsers");
  if (uaParserConfigs == null) {
    throw new IllegalArgumentException("user_agent_parsers is missing from yaml");
  }
  uaParser = UserAgentParser.fromList(uaParserConfigs);

  List<Map<String,String>> osParserConfigs = regexConfig.get("os_parsers");
  if (osParserConfigs == null) {
    throw new IllegalArgumentException("os_parsers is missing from yaml");
  }
  osParser = OSParser.fromList(osParserConfigs);

  List<Map<String,String>> deviceParserConfigs = regexConfig.get("device_parsers");
  if (deviceParserConfigs == null) {
    throw new IllegalArgumentException("device_parsers is missing from yaml");
  }
  deviceParser = DeviceParser.fromList(deviceParserConfigs);
}
 
開發者ID:childe,項目名稱:hangout,代碼行數:24,代碼來源:Parser.java

示例7: readConfigFile

import org.yaml.snakeyaml.constructor.SafeConstructor; //導入依賴的package包/類
public static Map readConfigFile(String filename) throws IOException {
    Map ret;
    Yaml yaml = new Yaml(new SafeConstructor());
    InputStream inputStream = new FileInputStream(new File(filename));

    try {
        ret = (Map)yaml.load(inputStream);
    } finally {
        inputStream.close();
    }

    if(ret == null) {
        ret = new HashMap();
    }

    return new HashMap(ret);
}
 
開發者ID:preems,項目名稱:realtime-event-processing,代碼行數:18,代碼來源:ConfigReader.java

示例8: testConstruct

import org.yaml.snakeyaml.constructor.SafeConstructor; //導入依賴的package包/類
@SuppressWarnings("unchecked")
public void testConstruct() {
    String doc = "- 5\n- Person\n- true";
    Yaml yaml = new Yaml(new SafeConstructor());
    List<Object> list = (List<Object>) yaml.load(doc);
    assertEquals(3, list.size());
    assertEquals(new Integer(5), list.get(0));
    assertEquals("Person", list.get(1));
    assertEquals(Boolean.TRUE, list.get(2));
}
 
開發者ID:bmoliveira,項目名稱:snake-yaml,代碼行數:11,代碼來源:SafeConstructorExampleTest.java

示例9: testSafeConstruct

import org.yaml.snakeyaml.constructor.SafeConstructor; //導入依賴的package包/類
public void testSafeConstruct() {
    String doc = "- 5\n- !org.yaml.snakeyaml.constructor.Person\n  firstName: Andrey\n  age: 99\n- true";
    Yaml yaml = new Yaml(new SafeConstructor());
    try {
        yaml.load(doc);
        fail("Custom Java classes should not be created.");
    } catch (Exception e) {
        assertEquals(
                "could not determine a constructor for the tag !org.yaml.snakeyaml.constructor.Person\n"
                        + " in 'string', line 2, column 3:\n"
                        + "    - !org.yaml.snakeyaml.constructor. ... \n" + "      ^\n",
                e.getMessage());
    }
}
 
開發者ID:bmoliveira,項目名稱:snake-yaml,代碼行數:15,代碼來源:SafeConstructorExampleTest.java

示例10: testDictSafeConstructor

import org.yaml.snakeyaml.constructor.SafeConstructor; //導入依賴的package包/類
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testDictSafeConstructor() {
    Map value = new TreeMap();
    value.put("abc", "www");
    value.put("qwerty", value);
    Yaml yaml = new Yaml(new SafeConstructor());
    String output1 = yaml.dump(value);
    assertEquals("&id001\nabc: www\nqwerty: *id001\n", output1);
    Map value2 = (Map) yaml.load(output1);
    assertEquals(2, value2.size());
    assertEquals("www", value2.get("abc"));
    assertTrue(value2.get("qwerty") instanceof Map);
    Map value3 = (Map) value2.get("qwerty");
    assertTrue(value3.get("qwerty") instanceof Map);
}
 
開發者ID:bmoliveira,項目名稱:snake-yaml,代碼行數:16,代碼來源:PyRecursiveTest.java

示例11: SpongeConfig

import org.yaml.snakeyaml.constructor.SafeConstructor; //導入依賴的package包/類
public SpongeConfig(File fh, Logger logger) {
    this.file = fh;
    this.yaml = new Yaml(new SafeConstructor());

    this.reload();

    logger.info(String.format("Data: %s", this.data));
}
 
開發者ID:TheArchives,項目名稱:ArchBlock,代碼行數:9,代碼來源:SpongeConfig.java

示例12: loadString

import org.yaml.snakeyaml.constructor.SafeConstructor; //導入依賴的package包/類
public ObjectNode loadString(String content)
    throws IOException
{
    // here doesn't use jackson-dataformat-yaml so that snakeyaml calls Resolver
    // and Composer. See also YamlTagResolver.
    Yaml yaml = new Yaml(new SafeConstructor(), new Representer(), new DumperOptions(), new YamlTagResolver());
    ObjectNode object = normalizeValidateObjectNode(yaml.load(content));
    return object;
}
 
開發者ID:treasure-data,項目名稱:digdag,代碼行數:10,代碼來源:YamlLoader.java

示例13: externalGroupsService

import org.yaml.snakeyaml.constructor.SafeConstructor; //導入依賴的package包/類
@Bean
@Autowired
public ExternalGroupsService externalGroupsService(
  @Value("${externalProviders.config.path}") final String configFileLocation) throws IOException {

  Yaml yaml = new Yaml(new SafeConstructor());

  @SuppressWarnings("unchecked")
  Map<String, List<Map<String, Object>>> config = (Map<String, List<Map<String, Object>>>) yaml.load(resourceLoader.getResource(configFileLocation).getInputStream());
  final List<Map<String, Object>> externalGroupProviders = config.get("externalGroupProviders");

  final List<Provider> groupClients = externalGroupProviders.stream().map(entryMap -> {
    final String type = (String) entryMap.get("type");
    final String url = StringUtils.trimTrailingCharacter((String) entryMap.get("url"), '/');
    final String schacHomeOrganization = (String) entryMap.get("schacHomeOrganization");
    final String name = (String) entryMap.get("name");
    final Integer timeoutMillis = (Integer) entryMap.get("timeoutMillis");
    @SuppressWarnings("unchecked") final Map<String, Object> rawCredentials = (Map<String, Object>) entryMap.get("credentials");
    String username = (String) rawCredentials.get("username");
    String secret = (String) rawCredentials.get("secret");

    GroupProviderType groupProviderType = GroupProviderType.valueOf(type.toUpperCase());

    final Provider.Configuration configuration = new Provider.Configuration(groupProviderType, url, new Provider.Configuration.Credentials(username, secret), timeoutMillis, schacHomeOrganization, name);
    switch (groupProviderType) {
      case VOOT2:
        return new Voot2Provider(configuration);
      case OPEN_SOCIAL:
        return new OpenSocialClient(configuration);
      case TEAMS:
        return new TeamsProviderClient(configuration);
      case OPEN_SOCIAL_MEMBERS:
        return new OpenSocialMembersClient(configuration);
      default:
        throw new IllegalArgumentException("Unknown external provider-type: " + type);
    }
  }).collect(Collectors.toList());
  return new ExternalGroupsService(groupClients, supportLinkedGrouperExternalGroups);
}
 
開發者ID:OpenConext,項目名稱:OpenConext-voot,代碼行數:40,代碼來源:VootServiceApplication.java

示例14: createConstructor

import org.yaml.snakeyaml.constructor.SafeConstructor; //導入依賴的package包/類
private static SafeConstructor createConstructor() {
    try {
        return constructor.getDeclaredConstructor().newInstance();
    } catch(Exception e) {
        ModuleManager.getLogger().log(Level.SEVERE, "Could not create YAML constructor.", e);
        return null;
    }
}
 
開發者ID:Steveice10,項目名稱:Peacecraft,代碼行數:9,代碼來源:YamlStorage.java

示例15: APTranslator

import org.yaml.snakeyaml.constructor.SafeConstructor; //導入依賴的package包/類
@SuppressWarnings("unchecked")
public APTranslator(InputStream APDBYAML, boolean full_apname) {
    this.full_apname = full_apname;
    // Load yaml database
    Yaml yaml = new Yaml(new SafeConstructor());
    Map<String,Object> regexConfig = (Map<String,Object>) yaml.load(APDBYAML);
    APNameDB = (Map<String, Map<String, String>>) regexConfig.get("apprefix_sjtu");
}
 
開發者ID:OMNILab,項目名稱:LiveWee,代碼行數:9,代碼來源:APTranslator.java


注:本文中的org.yaml.snakeyaml.constructor.SafeConstructor類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。