private static synchronized Set getOrCreateSingletonAllowedCities()

in ingestion-beam/src/main/java/com/mozilla/telemetry/decoder/GeoCityLookup.java [117:144]


  private static synchronized Set<Long> getOrCreateSingletonAllowedCities(String geoCityFilter)
      throws IOException {
    if (singletonAllowedCities == null) {
      InputStream inputStream;
      try {
        Metadata metadata = FileSystems.matchSingleFileSpec(geoCityFilter);
        ReadableByteChannel channel = FileSystems.open(metadata.resourceId());
        inputStream = Channels.newInputStream(channel);
      } catch (IOException e) {
        throw new IOException("Exception thrown while fetching configured geoCityFilter", e);
      }
      singletonAllowedCities = new HashSet<>();
      BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
      while (reader.ready()) {
        String line = reader.readLine();
        Matcher matcher = GEO_NAME_PATTERN.matcher(line);
        if (matcher.find()) {
          Long geoNameId = Long.valueOf(matcher.group(1));
          singletonAllowedCities.add(geoNameId);
        } else {
          throw new IllegalStateException(
              "Line of geoCityFilter file does not begin with a geoName integer ID: " + line);

        }
      }
    }
    return singletonAllowedCities;
  }