public final class Url extends Object
Neither of the built-in URL models offer direct access to path segments or query parameters.
Manually using StringBuilder to assemble these components is cumbersome: do '+'
characters get silently replaced with spaces? If a query parameter contains a '&', does that
get escaped? By offering methods to read and write individual query parameters directly,
application developers are saved from the hassles of encoding and decoding.
The URL (JDK1.0) and URI (Java 1.4) classes predate builders and instead use telescoping constructors. For example, there's no API to compose a URI with a custom port without also providing a query and fragment.
Instances of Url are well-formed and always have a scheme, host, and path. With
java.net.URL it's possible to create an awkward URL like http:/ with scheme and
path but no hostname. Building APIs that consume such malformed values is difficult!
This class has a modern API. It avoids punitive checked exceptions: get()
throws IllegalArgumentException on invalid input or parse()
returns null if the input is an invalid URL. You can even be explicit about whether each
component has been encoded already.
| Modifier and Type | Class and Description |
|---|---|
static class |
Url.Builder |
public static int defaultPort(String scheme)
public static void percentDecode(Buffer out, String encoded, int pos, int limit, boolean plusIsSpace)
public static String canonicalize(String input, String encodeSet, boolean alreadyEncoded, boolean strict, boolean plusIsSpace, boolean asciiOnly, Charset charset)
public static String canonicalize(String input, String encodeSet, boolean alreadyEncoded, boolean strict, boolean plusIsSpace, boolean asciiOnly)
public URL url()
public URI uri()
public String scheme()
public boolean isHttps()
public String encodedUsername()
public String username()
public String encodedPassword()
public String password()
public String host()
public int port()
public int pathSize()
public String encodedPath()
public String encodedQuery()
public String query()
public int querySize()
public String queryParameterName(int index)
public String queryParameterValue(int index)
public String encodedFragment()
public String fragment()
public String redact()
public Url.Builder newBuilder()
public Url.Builder newBuilder(String link)
public String topPrivateDomain()
Copyright © 2019. All rights reserved.