Java Code Examples for java.net.URI.getRawFragment()

The following are Jave code examples for showing how to use getRawFragment() of the java.net.URI class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Hotspot-master-devp   File: URIBuilder.java   View Source Code Vote up 5 votes
private void digestURI(final URI uri) {
    this.scheme = uri.getScheme();
    this.encodedSchemeSpecificPart = uri.getRawSchemeSpecificPart();
    this.encodedAuthority = uri.getRawAuthority();
    this.host = uri.getHost();
    this.port = uri.getPort();
    this.encodedUserInfo = uri.getRawUserInfo();
    this.userInfo = uri.getUserInfo();
    this.encodedPath = uri.getRawPath();
    this.path = uri.getPath();
    this.encodedQuery = uri.getRawQuery();
    this.queryParams = parseQuery(uri.getRawQuery(), Charset.forName(HTTP.UTF_8));
    this.encodedFragment = uri.getRawFragment();
    this.fragment = uri.getFragment();
}
 
Example 2
Project: lams   File: URIBuilder.java   View Source Code Vote up 5 votes
private void digestURI(final URI uri) {
    this.scheme = uri.getScheme();
    this.encodedSchemeSpecificPart = uri.getRawSchemeSpecificPart();
    this.encodedAuthority = uri.getRawAuthority();
    this.host = uri.getHost();
    this.port = uri.getPort();
    this.encodedUserInfo = uri.getRawUserInfo();
    this.userInfo = uri.getUserInfo();
    this.encodedPath = uri.getRawPath();
    this.path = uri.getPath();
    this.encodedQuery = uri.getRawQuery();
    this.queryParams = parseQuery(uri.getRawQuery(), Consts.UTF_8);
    this.encodedFragment = uri.getRawFragment();
    this.fragment = uri.getFragment();
}
 
Example 3
Project: FirefoxData-android   File: URIBuilder.java   View Source Code Vote up 5 votes
private void digestURI(final URI uri) {
    this.scheme = uri.getScheme();
    this.encodedSchemeSpecificPart = uri.getRawSchemeSpecificPart();
    this.encodedAuthority = uri.getRawAuthority();
    this.host = uri.getHost();
    this.port = uri.getPort();
    this.encodedUserInfo = uri.getRawUserInfo();
    this.userInfo = uri.getUserInfo();
    this.encodedPath = uri.getRawPath();
    this.path = uri.getPath();
    this.encodedQuery = uri.getRawQuery();
    this.queryParams = parseQuery(uri.getRawQuery(), Consts.UTF_8);
    this.encodedFragment = uri.getRawFragment();
    this.fragment = uri.getFragment();
}
 
Example 4
Project: FirefoxData-android   File: HMACAuthHeaderProvider.java   View Source Code Vote up 5 votes
/**
 * Generate an HMAC request string.
 * <p>
 * This method trusts its inputs to be valid as per the MAC Authentication spec.
 *
 * @param request HTTP request.
 * @param timestamp to use.
 * @param nonce to use.
 * @param extra to use.
 * @return request string.
 */
protected static String getRequestString(HttpUriRequest request, long timestamp, String nonce, String extra) {
  String method = request.getMethod().toUpperCase();

  URI uri = request.getURI();
  String host = uri.getHost();

  String path = uri.getRawPath();
  if (uri.getRawQuery() != null) {
    path += "?";
    path += uri.getRawQuery();
  }
  if (uri.getRawFragment() != null) {
    path += "#";
    path += uri.getRawFragment();
  }

  int port = uri.getPort();
  String scheme = uri.getScheme();
  if (port != -1) {
  } else if ("http".equalsIgnoreCase(scheme)) {
    port = 80;
  } else if ("https".equalsIgnoreCase(scheme)) {
    port = 443;
  } else {
    throw new IllegalArgumentException("Unsupported URI scheme: " + scheme + ".");
  }

  String requestString = timestamp + "\n" +
      nonce       + "\n" +
      method      + "\n" +
      path        + "\n" +
      host        + "\n" +
      port        + "\n" +
      extra       + "\n";

  return requestString;
}
 
Example 5
Project: openjdk-jdk10   File: UnixFileSystemProvider.java   View Source Code Vote up 5 votes
private void checkUri(URI uri) {
    if (!uri.getScheme().equalsIgnoreCase(getScheme()))
        throw new IllegalArgumentException("URI does not match this provider");
    if (uri.getRawAuthority() != null)
        throw new IllegalArgumentException("Authority component present");
    String path = uri.getPath();
    if (path == null)
        throw new IllegalArgumentException("Path component is undefined");
    if (!path.equals("/"))
        throw new IllegalArgumentException("Path component should be '/'");
    if (uri.getRawQuery() != null)
        throw new IllegalArgumentException("Query component present");
    if (uri.getRawFragment() != null)
        throw new IllegalArgumentException("Fragment component present");
}
 
Example 6
Project: openjdk-jdk10   File: WindowsFileSystemProvider.java   View Source Code Vote up 5 votes
private void checkUri(URI uri) {
    if (!uri.getScheme().equalsIgnoreCase(getScheme()))
        throw new IllegalArgumentException("URI does not match this provider");
    if (uri.getRawAuthority() != null)
        throw new IllegalArgumentException("Authority component present");
    String path = uri.getPath();
    if (path == null)
        throw new IllegalArgumentException("Path component is undefined");
    if (!path.equals("/"))
        throw new IllegalArgumentException("Path component should be '/'");
    if (uri.getRawQuery() != null)
        throw new IllegalArgumentException("Query component present");
    if (uri.getRawFragment() != null)
        throw new IllegalArgumentException("Fragment component present");
}
 
Example 7
Project: vase   File: HttpUtils.java   View Source Code Vote up 5 votes
public static String relativePath(String line) throws RuntimeException {
    String connects[] = line.split(" +");
    if (connects[1].toLowerCase().startsWith("http://")) {
        URI uri = Uri.create(connects[1]);
        String path = uri.getRawPath();
        String query = uri.getRawQuery();
        String frag = uri.getRawFragment();

        if (path == null) {
            path = "/";
        }

        if (query == null) {
            query = "";
        } else {
            query = "?" + query;
        }

        if (frag == null) {
            frag = "";
        } else {
            frag = "#" + frag;
        }
        return connects[0] + " " + path + query + frag + " " + connects[2];
    } else {
        return line;
    }
}
 
Example 8
Project: incubator-netbeans   File: HgURL.java   View Source Code Vote up 4 votes
/**
 *
 * @param urlString
 * @param username
 * @param password value is cloned, if you want to null the field, call {@link #clearPassword()}
 * @throws URISyntaxException
 */
public HgURL(String urlString, String username, char[] password) throws URISyntaxException {
    URI originalUri;

    if (urlString == null) {
        throw new IllegalArgumentException("<null> URL string");    //NOI18N
    }

    if (urlString.length() == 0) {
        throw new IllegalArgumentException("empty URL string");     //NOI18N
    }

    if (looksLikePlainFilePath(urlString)) {
        originalUri = new File(urlString).toURI();
        scheme = Scheme.FILE;
    } else {
        originalUri = new URI(urlString).parseServerAuthority();
        String originalScheme = originalUri.getScheme();
        scheme = (originalScheme != null) ? determineScheme(originalScheme)
                                          : null;
    }

    if (scheme == null) {
        throw new URISyntaxException(
                urlString,
                NbBundle.getMessage(HgURL.class,
                                    "MSG_UNSUPPORTED_PROTOCOL",     //NOI18N
                                    originalUri.getScheme()));
    }

    verifyUserInfoData(scheme, username, password);

    if (username != null) {
        this.username = username;
        this.password = password == null ? null : (char[])password.clone();
    } else {
        String rawUserInfo = originalUri.getRawUserInfo();
        if (rawUserInfo == null) {
            this.username = null;
            this.password = null;
        } else {
            int colonIndex = rawUserInfo.indexOf(':');
            if (colonIndex == -1) {
                this.username = rawUserInfo;
                this.password = null;
            } else {
                this.username = rawUserInfo.substring(0, colonIndex);
                this.password = rawUserInfo.substring(colonIndex + 1).toCharArray();
            }
        }
    }

    host = originalUri.getHost();
    port = originalUri.getPort();
    rawPath     = originalUri.getRawPath();
    rawQuery    = originalUri.getRawQuery();
    rawFragment = originalUri.getRawFragment();

    path = originalUri.getPath();
}
 
Example 9
Project: FirefoxData-android   File: HawkAuthHeaderProvider.java   View Source Code Vote up 4 votes
/**
 * Generate a normalized Hawk request string. This is under-specified; the
 * code here was reverse engineered from the code at
 * <a href="https://github.com/hueniverse/hawk/blob/871cc597973110900467bd3dfb84a3c892f678fb/lib/crypto.js#L55">https://github.com/hueniverse/hawk/blob/871cc597973110900467bd3dfb84a3c892f678fb/lib/crypto.js#L55</a>.
 * <p>
 * This method trusts its inputs to be valid.
 */
protected static String getRequestString(HttpUriRequest request, String type, long timestamp, String nonce, String hash, String extra, String app, String dlg) {
  String method = request.getMethod().toUpperCase(Locale.US);

  URI uri = request.getURI();
  String host = uri.getHost();

  String path = uri.getRawPath();
  if (uri.getRawQuery() != null) {
    path += "?";
    path += uri.getRawQuery();
  }
  if (uri.getRawFragment() != null) {
    path += "#";
    path += uri.getRawFragment();
  }

  int port = uri.getPort();
  String scheme = uri.getScheme();
  if (port != -1) {
  } else if ("http".equalsIgnoreCase(scheme)) {
    port = 80;
  } else if ("https".equalsIgnoreCase(scheme)) {
    port = 443;
  } else {
    throw new IllegalArgumentException("Unsupported URI scheme: " + scheme + ".");
  }

  StringBuilder sb = new StringBuilder();
  sb.append("hawk.");
  sb.append(HAWK_HEADER_VERSION);
  sb.append('.');
  sb.append(type);
  sb.append('\n');
  sb.append(timestamp);
  sb.append('\n');
  sb.append(nonce);
  sb.append('\n');
  sb.append(method);
  sb.append('\n');
  sb.append(path);
  sb.append('\n');
  sb.append(host);
  sb.append('\n');
  sb.append(port);
  sb.append('\n');
  if (hash != null) {
    sb.append(hash);
  }
  sb.append("\n");
  if (extra != null && extra.length() > 0) {
    sb.append(escapeExtraString(extra));
  }
  sb.append("\n");
  if (app != null) {
    sb.append(app);
    sb.append("\n");
    if (dlg != null) {
      sb.append(dlg);
    }
    sb.append("\n");
  }

  return sb.toString();
}
 
Example 10
Project: openjdk-jdk10   File: WindowsUriSupport.java   View Source Code Vote up 4 votes
/**
 * Converts given URI to a Path
 */
static WindowsPath fromUri(WindowsFileSystem fs, URI uri) {
    if (!uri.isAbsolute())
        throw new IllegalArgumentException("URI is not absolute");
    if (uri.isOpaque())
        throw new IllegalArgumentException("URI is not hierarchical");
    String scheme = uri.getScheme();
    if ((scheme == null) || !scheme.equalsIgnoreCase("file"))
        throw new IllegalArgumentException("URI scheme is not \"file\"");
    if (uri.getRawFragment() != null)
        throw new IllegalArgumentException("URI has a fragment component");
    if (uri.getRawQuery() != null)
        throw new IllegalArgumentException("URI has a query component");
    String path = uri.getPath();
    if (path.equals(""))
        throw new IllegalArgumentException("URI path component is empty");

    // UNC
    String auth = uri.getRawAuthority();
    if (auth != null && !auth.equals("")) {
        String host = uri.getHost();
        if (host == null)
            throw new IllegalArgumentException("URI authority component has undefined host");
        if (uri.getUserInfo() != null)
            throw new IllegalArgumentException("URI authority component has user-info");
        if (uri.getPort() != -1)
            throw new IllegalArgumentException("URI authority component has port number");

        // IPv6 literal
        // 1. drop enclosing brackets
        // 2. replace ":" with "-"
        // 3. replace "%" with "s" (zone/scopeID delimiter)
        // 4. Append .ivp6-literal.net
        if (host.startsWith("[")) {
            host = host.substring(1, host.length()-1)
                       .replace(':', '-')
                       .replace('%', 's');
            host += IPV6_LITERAL_SUFFIX;
        }

        // reconstitute the UNC
        path = "\\\\" + host + path;
    } else {
        if ((path.length() > 2) && (path.charAt(2) == ':')) {
            // "/c:/foo" --> "c:/foo"
            path = path.substring(1);
        }
    }
    return WindowsPath.parse(fs, path);
}
 
Example 11
Project: openjdk-jdk10   File: File.java   View Source Code Vote up 3 votes
/**
 * Creates a new {@code File} instance by converting the given
 * {@code file:} URI into an abstract pathname.
 *
 * <p> The exact form of a {@code file:} URI is system-dependent, hence
 * the transformation performed by this constructor is also
 * system-dependent.
 *
 * <p> For a given abstract pathname <i>f</i> it is guaranteed that
 *
 * <blockquote><code>
 * new File(</code><i>&nbsp;f</i><code>.{@link #toURI()
 * toURI}()).equals(</code><i>&nbsp;f</i><code>.{@link #getAbsoluteFile() getAbsoluteFile}())
 * </code></blockquote>
 *
 * so long as the original abstract pathname, the URI, and the new abstract
 * pathname are all created in (possibly different invocations of) the same
 * Java virtual machine.  This relationship typically does not hold,
 * however, when a {@code file:} URI that is created in a virtual machine
 * on one operating system is converted into an abstract pathname in a
 * virtual machine on a different operating system.
 *
 * @param  uri
 *         An absolute, hierarchical URI with a scheme equal to
 *         {@code "file"}, a non-empty path component, and undefined
 *         authority, query, and fragment components
 *
 * @throws  NullPointerException
 *          If {@code uri} is {@code null}
 *
 * @throws  IllegalArgumentException
 *          If the preconditions on the parameter do not hold
 *
 * @see #toURI()
 * @see java.net.URI
 * @since 1.4
 */
public File(URI uri) {

    // Check our many preconditions
    if (!uri.isAbsolute())
        throw new IllegalArgumentException("URI is not absolute");
    if (uri.isOpaque())
        throw new IllegalArgumentException("URI is not hierarchical");
    String scheme = uri.getScheme();
    if ((scheme == null) || !scheme.equalsIgnoreCase("file"))
        throw new IllegalArgumentException("URI scheme is not \"file\"");
    if (uri.getRawAuthority() != null)
        throw new IllegalArgumentException("URI has an authority component");
    if (uri.getRawFragment() != null)
        throw new IllegalArgumentException("URI has a fragment component");
    if (uri.getRawQuery() != null)
        throw new IllegalArgumentException("URI has a query component");
    String p = uri.getPath();
    if (p.equals(""))
        throw new IllegalArgumentException("URI path component is empty");

    // Okay, now initialize
    p = fs.fromURIPath(p);
    if (File.separatorChar != '/')
        p = p.replace('/', File.separatorChar);
    this.path = fs.normalize(p);
    this.prefixLength = fs.prefixLength(this.path);
}