public static String concatUfsPath(String base, String path) {
    Pattern basePattern = Pattern.compile("(...)\\/\\/");
    // use conCatPath to join path if base is not starting with //
    if (!basePattern.matcher(base).matches()) {
      return concatPath(base, path);
    } else {
      Preconditions.checkArgument(base != null, "Failed to concatPath: base is null");
      Preconditions.checkArgument(path != null, "Failed to concatPath: a null set of paths");
      String trimmedPath = SEPARATOR_MATCHER.trimFrom(path);
      StringBuilder output = new StringBuilder(base.length() + trimmedPath.length());
      output.append(base);
      output.append(trimmedPath);
      return output.toString();
    }
  }
@Test
  public void concatUfsPath() {
    assertEquals("s3://", PathUtils.concatUfsPath("s3://", ""));
    assertEquals("s3://bar", PathUtils.concatUfsPath("s3://", "bar"));

    assertEquals("hdfs://localhost:9010",
        PathUtils.concatUfsPath("hdfs://localhost:9010/", ""));
    assertEquals("hdfs://localhost:9010/bar",
        PathUtils.concatUfsPath("hdfs://localhost:9010/", "bar"));

    assertEquals("s3://foo", PathUtils.concatUfsPath("s3://foo", ""));
    assertEquals("hdfs://localhost:9010/foo",
        PathUtils.concatUfsPath("hdfs://localhost:9010/foo", ""));

    // Join base without trailing "/"
    assertEquals("s3://foo/bar", PathUtils.concatUfsPath("s3://foo", "bar"));
    assertEquals("s3://foo/bar", PathUtils.concatUfsPath("s3://foo", "bar/"));
    assertEquals("s3://foo/bar", PathUtils.concatUfsPath("s3://foo", "/bar"));
    assertEquals("s3://foo/bar", PathUtils.concatUfsPath("s3://foo", "/bar/"));

    assertEquals("hdfs://localhost:9010/foo/bar",
        PathUtils.concatUfsPath("hdfs://localhost:9010/foo", "bar"));
    assertEquals("hdfs://localhost:9010/foo/bar",
        PathUtils.concatUfsPath("hdfs://localhost:9010/foo", "bar/"));
    assertEquals("hdfs://localhost:9010/foo/bar",
        PathUtils.concatUfsPath("hdfs://localhost:9010/foo", "/bar"));
    assertEquals("hdfs://localhost:9010/foo/bar",
        PathUtils.concatUfsPath("hdfs://localhost:9010/foo", "/bar/"));

    // Join base with trailing "/"
    assertEquals("s3://foo/bar", PathUtils.concatUfsPath("s3://foo/", "bar"));
    assertEquals("s3://foo/bar", PathUtils.concatUfsPath("s3://foo/", "bar/"));
    assertEquals("s3://foo/bar", PathUtils.concatUfsPath("s3://foo/", "/bar"));
    assertEquals("s3://foo/bar", PathUtils.concatUfsPath("s3://foo/", "/bar/"));

    assertEquals("hdfs://localhost:9010/foo/bar",
        PathUtils.concatUfsPath("hdfs://localhost:9010/foo/", "bar"));
    assertEquals("hdfs://localhost:9010/foo/bar",
        PathUtils.concatUfsPath("hdfs://localhost:9010/foo/", "bar/"));
    assertEquals("hdfs://localhost:9010/foo/bar",
        PathUtils.concatUfsPath("hdfs://localhost:9010/foo/", "/bar"));
    assertEquals("hdfs://localhost:9010/foo/bar",
        PathUtils.concatUfsPath("hdfs://localhost:9010/foo/", "/bar/"));

    // Redundant separator must be trimmed.
    assertEquals("s3://foo/bar", PathUtils.concatUfsPath("s3://foo/", "bar//"));
    assertEquals("hdfs://localhost:9010/foo/bar",
        PathUtils.concatUfsPath("hdfs://localhost:9010/foo/", "bar//"));
  }