HttpUrl { static HttpUrl getChecked(String url) throws MalformedURLException, UnknownHostException { Builder builder = new Builder(); Builder.ParseResult result = builder.parse(null, url); switch (result) { case SUCCESS: return builder.build(); case INVALID_HOST: throw new UnknownHostException("Invalid host: " + url); case UNSUPPORTED_SCHEME: case MISSING_SCHEME: case INVALID_PORT: default: throw new MalformedURLException("Invalid URL: " + result + " for " + url); } } private  HttpUrl(Builder builder); URL url(); URI uri(); String scheme(); boolean isHttps(); String encodedUsername(); String username(); String encodedPassword(); String password(); String host(); int port(); static int defaultPort(String scheme); int pathSize(); String encodedPath(); List<String> encodedPathSegments(); List<String> pathSegments(); String encodedQuery(); String query(); int querySize(); String queryParameter(String name); Set<String> queryParameterNames(); List<String> queryParameterValues(String name); String queryParameterName(int index); String queryParameterValue(int index); String encodedFragment(); String fragment(); HttpUrl resolve(String link); Builder newBuilder(); Builder newBuilder(String link); static HttpUrl parse(String url); static HttpUrl get(URL url); static HttpUrl get(URI uri); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); static int skipLeadingAsciiWhitespace(String input, int pos, int limit); static int skipTrailingAsciiWhitespace(String input, int pos, int limit); static int delimiterOffset(String input, int pos, int limit, String delimiters); static int delimiterOffset(String input, int pos, int limit, char delimiter); static String domainToAscii(String input); static byte[] utf8Bytes(int codePoint); static void writeUtf8CodePoint(ByteBuffer byteBuffer, int codePoint); static String readUtf8String(ByteBuffer byteBuffer);  }
@Test public void fromJavaNetUrlUnsupportedScheme_checked() throws Exception { try { HttpUrl.getChecked("mailto:user@example.com"); fail(); } catch (MalformedURLException e) { } }
@Test public void fromJavaNetUrlBadHost_checked() throws Exception { try { HttpUrl.getChecked("http: fail(); } catch (UnknownHostException expected) { } }