public static URI getFileURI(String uriStr, URI fullUriForPathOnlyUriStr)
      throws URISyntaxException {
    uriStr = sanitizeURIString(uriStr);
    URI fileURI = URI.create(uriStr);
    if (fileURI.getScheme() == null) {
      return new URI(fullUriForPathOnlyUriStr.getScheme(), fullUriForPathOnlyUriStr.getUserInfo(),
          fullUriForPathOnlyUriStr.getHost(), fullUriForPathOnlyUriStr.getPort(), fileURI.getPath(), fileURI.getQuery(),
          fileURI.getFragment());
    }

    return fileURI;
  }
@Test
  public void testGetFileURI()
      throws Exception {
    // Raw path without scheme
    Assert.assertEquals(SegmentGenerationUtils.getFileURI("/path/to/file", new URI("file:/path/to")).toString(),
        "file:/path/to/file");
    Assert
        .assertEquals(SegmentGenerationUtils.getFileURI("/path/to/file", new URI("hdfs://namenode/path/to")).toString(),
            "hdfs://namenode/path/to/file");
    Assert.assertEquals(SegmentGenerationUtils.getFileURI("/path/to/file", new URI("hdfs:///path/to")).toString(),
        "hdfs:/path/to/file");

    // Typical local file URI
    validateFileURI(new URI("file:/path/to/"));
    // Remote hostname.
    validateFileURI(new URI("file://hostname/path/to/"));
    // Local hostname
    validateFileURI(new URI("file:///path/to/"), "file:/path/to/");

    // Regular HDFS path
    validateFileURI(new URI("hdfs:///path/to/"), "hdfs:/path/to/");

    // Namenode as authority, plus non-standard port
    validateFileURI(new URI("hdfs://namenode:9999/path/to/"));

    // S3 bucket + path
    validateFileURI(new URI("s3://bucket/path/to/"));

    // S3 URI with userInfo (username/password)
    validateFileURI(new URI("s3://username:password@bucket/path/to/"));
  }