Example #1
0
  /**
   * decode the raw URI to get the underlying URI
   *
   * @param rawURI raw Har URI
   * @return filtered URI of the underlying fileSystem
   */
  private URI decodeHarURI(URI rawURI, Configuration conf) throws IOException {
    String tmpAuth = rawURI.getAuthority();
    // we are using the default file
    // system in the config
    // so create a underlying uri and
    // return it
    if (tmpAuth == null) {
      // create a path
      return FileSystem.getDefaultUri(conf);
    }
    String authority = rawURI.getAuthority();
    if (authority == null) {
      throw new IOException(
          "URI: "
              + rawURI
              + " is an invalid Har URI since authority==null."
              + "  Expecting har://<scheme>-<host>/<path>.");
    }

    int i = authority.indexOf('-');
    if (i < 0) {
      throw new IOException(
          "URI: "
              + rawURI
              + " is an invalid Har URI since '-' not found."
              + "  Expecting har://<scheme>-<host>/<path>.");
    }

    if (rawURI.getQuery() != null) {
      // query component not allowed
      throw new IOException("query component in Path not supported  " + rawURI);
    }

    URI tmp;
    try {
      // convert <scheme>-<host> to <scheme>://<host>
      URI baseUri = new URI(authority.replaceFirst("-", "://"));

      tmp =
          new URI(
              baseUri.getScheme(),
              baseUri.getAuthority(),
              rawURI.getPath(),
              rawURI.getQuery(),
              rawURI.getFragment());
    } catch (URISyntaxException e) {
      throw new IOException(
          "URI: " + rawURI + " is an invalid Har URI. Expecting har://<scheme>-<host>/<path>.");
    }
    return tmp;
  }