private void initialize(InputStream regexYaml, boolean disableCache) { 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"); } List<String> mobileUAFamiliesList = regexConfig.get("mobile_user_agent_families"); List<String> mobileOSFamiliesList = regexConfig.get("mobile_os_families"); Set<String> mobileUAFamilies = (mobileUAFamiliesList == null ? Collections.EMPTY_SET : new HashSet<String>(mobileUAFamiliesList)); Set<String> mobileOSFamilies = (mobileOSFamiliesList == null ? Collections.EMPTY_SET : new HashSet<String>(mobileOSFamiliesList)); deviceParser = DeviceParser.fromList(deviceParserConfigs, uaParser, mobileUAFamilies, mobileOSFamilies); this.disableCache = disableCache; if (!disableCache) { uaCache = CacheBuilder.newBuilder() .maximumSize(MAX_CACHE_SIZE) .initialCapacity(MIN_CACHE_SIZE) .concurrencyLevel(1) .build(); } }
public UserAgent parseUserAgent(String agentString) { return uaParser.parse(agentString); }