Java 类org.yaml.snakeyaml.constructor.SafeConstructor 实例源码

项目:snake-yaml    文件:SingleQuoteTest.java   
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"));
}
项目:snake-yaml    文件:PyRecursiveTest.java   
@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);
}
项目:netty-cookbook    文件:Parser.java   
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);
}
项目:netty-cookbook    文件:Parser.java   
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);
}
项目:netty-cookbook    文件:Parser.java   
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);
}
项目:netty-cookbook    文件:Parser.java   
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);
}
项目:netty-cookbook    文件:Parser.java   
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);
}
项目:netty-cookbook    文件:Parser.java   
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);
}
项目:netty-cookbook    文件:Parser.java   
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);
}
项目:netty-cookbook    文件:Parser.java   
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);
}
项目:web-crawler    文件:WebCrawlerTopology.java   
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);
}
项目:senti-storm    文件:Configuration.java   
@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;
}
项目:hangout    文件:Parser.java   
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);
}
项目:snakeyaml    文件:SingleQuoteTest.java   
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"));
}
项目:snakeyaml    文件:PyRecursiveTest.java   
@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);
}
项目:realtime-event-processing    文件:ConfigReader.java   
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);
}
项目:storm-apps    文件:Configuration.java   
@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;
}
项目:snake-yaml    文件:SafeConstructorExampleTest.java   
@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));
}
项目:snake-yaml    文件:SafeConstructorExampleTest.java   
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());
    }
}
项目:snake-yaml    文件:PyRecursiveTest.java   
@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);
}
项目:ArchBlock    文件:SpongeConfig.java   
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));
}
项目:digdag    文件:YamlLoader.java   
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;
}
项目:OpenConext-voot    文件:VootServiceApplication.java   
@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);
}
项目:snakeyaml    文件:SafeConstructorExampleTest.java   
@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));
}
项目:snakeyaml    文件:SafeConstructorExampleTest.java   
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());
    }
}
项目:snakeyaml    文件:PyRecursiveTest.java   
@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);
}
项目:Peacecraft    文件:YamlStorage.java   
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;
    }
}
项目:LiveWee    文件:APTranslator.java   
@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");
}
项目:incubator-storm    文件:Utils.java   
public static Map findAndReadConfigFile(String name, boolean mustExist) {
    try {
        HashSet<URL> resources = new HashSet<URL>(findResources(name));
        if(resources.isEmpty()) {
            if(mustExist) throw new RuntimeException("Could not find config file on classpath " + name);
            else return new HashMap();
        }
        if(resources.size() > 1) {
            throw new RuntimeException("Found multiple " + name + " resources. You're probably bundling the Storm jars with your topology jar. "
              + resources);
        }
        URL resource = resources.iterator().next();
        Yaml yaml = new Yaml(new SafeConstructor());
        Map ret = null;
        InputStream input = resource.openStream();
        try {
            ret = (Map) yaml.load(new InputStreamReader(input));
        } finally {
            input.close();
        }
        if(ret==null) ret = new HashMap();


        return new HashMap(ret);

    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
项目:Apocalyptic    文件:Configuration.java   
public Configuration(File file) {
    super(new HashMap());

    DumperOptions options = new DumperOptions();
    options.setIndent(4);
    options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);

    this.yaml = new Yaml(new SafeConstructor(), new Representer(), options);

    this.file = file;
}
项目:piggybox    文件:ServiceCategoryClassify.java   
@SuppressWarnings("unchecked")
public ServiceCategoryClassify(InputStream regexYaml) {
    // Initialize the classification engine
    Yaml yaml = new Yaml(new SafeConstructor());
    Map<String,Object> regexConfig = (Map<String,Object>) yaml.load(regexYaml);
    List<Map<String, String>> hostRegexes = (List<Map<String, String>>) regexConfig.get("host_parser");
    //System.out.println(hostRegexes);
    for(Map<String, String> hostRegex : hostRegexes)
        hostParser.add(new HostPattern(hostRegex.get("regex"), hostRegex.get("category")));
    categoryClassesParser = (Map<String, Map<String, Integer>>) regexConfig.get("category_classes");
    subCategory1Parser = (Map<Integer, String>) regexConfig.get("cls1_map");
}
项目:piggybox    文件:GetAPBuildingInfo.java   
@SuppressWarnings("unchecked")
public GetAPBuildingInfo(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");
    //System.out.println(APNameDB);
}
项目:sftp-sync    文件:YAMLProcessor.java   
public YAMLProcessor(File file, boolean writeDefaults, YAMLFormat format) {
    super(new HashMap<String, Object>(), writeDefaults);

    DumperOptions options = new DumperOptions();
    options.setIndent(4);
    options.setDefaultFlowStyle(format.getStyle());
    Representer representer = new Representer();
    representer.setDefaultFlowStyle(format.getStyle());

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

    this.file = file;
}
项目:gletscher    文件:Configuration.java   
@SuppressWarnings("unchecked")
public static Configuration fromFile(Path configFile) throws IOException {
  Yaml yaml = new Yaml(new SafeConstructor());
  Map<String, Object> result =
      (Map<String, Object>)
          yaml.load(Files.newBufferedReader(configFile, StandardCharsets.UTF_8));
  return new Configuration(configFile.getFileSystem(), result);
}
项目:aphelion    文件:GameConfig.java   
public static List<Object> loadYaml(InputStream in) throws YAMLException
{
        // SafeConstructor because we may not trust the server or a moderator
        Yaml yaml = new Yaml(new SafeConstructor());
        List<Object> ret = new ArrayList<>();

        // parse the documents immediately (by invoking the iterator)
        for (Object o : yaml.loadAll(in))
        {
                ret.add(o);
        }
        return ret;
}
项目:aphelion    文件:GameConfig.java   
public static List<Object> loadYaml(String str) throws YAMLException
{
        // SafeConstructor because we may not trust the server or a moderator
        Yaml yaml = new Yaml(new SafeConstructor());
        List<Object> ret = new ArrayList<>();

        // parse the documents immediately (by invoking the iterator)
        for (Object o : yaml.loadAll(str))
        {
                ret.add(o);
        }
        return ret;
}
项目:piggybox    文件:ServiceCategoryClassify.java   
@SuppressWarnings("unchecked")
public ServiceCategoryClassify(InputStream regexYaml) {
    // Initialize the classification engine
    Yaml yaml = new Yaml(new SafeConstructor());
    Map<String,Object> regexConfig = (Map<String,Object>) yaml.load(regexYaml);
    List<Map<String, String>> hostRegexes = (List<Map<String, String>>) regexConfig.get("host_parser");
    //System.out.println(hostRegexes);
    for(Map<String, String> hostRegex : hostRegexes)
        hostParser.add(new HostPattern(hostRegex.get("regex"), hostRegex.get("category")));
    categoryClassesParser = (Map<String, Map<String, Integer>>) regexConfig.get("category_classes");
    subCategory1Parser = (Map<Integer, String>) regexConfig.get("cls1_map");
}
项目:piggybox    文件:GetAPBuildingInfo.java   
@SuppressWarnings("unchecked")
public GetAPBuildingInfo(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");
    //System.out.println(APNameDB);
}
项目:t4f-data    文件:SafeConstructorExampleTest.java   
@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));
}
项目:t4f-data    文件:SafeConstructorExampleTest.java   
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(
                "null; could not determine a constructor for the tag !org.yaml.snakeyaml.constructor.Person;  in 'string', line 2, column 3:\n    - !org.yaml.snakeyaml.constructor. ... \n      ^",
                e.getMessage());
    }
}