private List readPairsFromFile()

in ingestion-beam/src/main/java/com/mozilla/telemetry/contextualservices/ParseReportingUrl.java [442:472]


  private List<String[]> readPairsFromFile(String fileLocation, String paramName)
      throws IOException {
    if (fileLocation == null) {
      throw new IllegalArgumentException("--" + paramName + " must be defined");
    }

    try (InputStream inputStream = BeamFileInputStream.open(fileLocation);
        InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
        BufferedReader reader = new BufferedReader(inputStreamReader)) {
      List<String[]> pairs = new ArrayList<>();

      while (reader.ready()) {
        String line = reader.readLine();

        if (line != null && !line.isEmpty()) {
          String[] separated = line.split(",");

          if (separated.length != 2) {
            throw new IllegalArgumentException(
                "Invalid mapping: " + line + "; two-column csv expected");
          }

          pairs.add(separated);
        }
      }

      return pairs;
    } catch (IOException e) {
      throw new IOException("Exception thrown while fetching " + paramName, e);
    }
  }