/*
 * Copyright 2018 The Data Transfer Project Authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.dataportabilityproject.security;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.google.common.collect.ImmutableList;
import java.io.IOException;
import java.io.InputStream;
import java.io.SequenceInputStream;
import java.util.Map;

// TODO(rtannenbaum): Move this out of security/ into a new module config/. Couldn't figure it
// out in Intellij.
public class ConfigUtils {
  public static Map<String, Object> parse(InputStream in) throws IOException {
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    return mapper.readValue(in, Map.class);
  }

  public static InputStream getSettingsCombinedInputStream(ImmutableList<String> settingsFiles) {
    return settingsFiles.stream()
        .map(file -> ConfigUtils.class.getClassLoader().getResourceAsStream(file))
        .reduce(null, (in1, in2) -> combineStreams(in1, in2));
  }

  private static InputStream combineStreams(InputStream in1, InputStream in2) {
    if (in1 != null) {
      if (in2 != null) {
        return new SequenceInputStream(in1, in2);
      }
      return in1;
    }
    // in1 == null
    if (in2 != null) {
      return in2;
    }
    return null;
  }
}

@@ -1047,34 +1047,200 @@
 ij.%0A
-public class ConfigUtils %7B
+/**%0A * Common utilities for yaml configuration parsing.%0A */%0Apublic class ConfigUtils %7B%0A%0A  /**%0A   * Parses an input stream to a yaml configuration file into a generic Map%3CString, Object%3E.%0A   */
 %0A  p
@@ -1427,16 +1427,144 @@
 );%0A  %7D%0A%0A
+  /**%0A   * Concatenates %7B@link InputStream%7Ds to multiple yaml configuration files into a single%0A   * %7B@link InputStream%7D.%0A   */%0A
   public
@@ -1838,16 +1838,72 @@
 );%0A  %7D%0A%0A
+  /**%0A   * Concatenates two %7B@link InputStream%7Ds.%0A   */%0A
   privat

Document ConfigUtils methods