Here you can find the source of createUrl(final String spec)
Parameter | Description |
---|---|
spec | URL spec to create a URL from |
Parameter | Description |
---|---|
IllegalArgumentException | if the specified URL spec is a malformed URL |
public static URL createUrl(final String spec) throws IllegalArgumentException
//package com.java2s; //License from project: Apache License import java.net.MalformedURLException; import java.net.URL; public class Main { /**//from www . j ava2 s.com * Creates a new {@link URL} from the specified URL spec. * * <p> * Primary goal of this factory method is to suppress the {@link MalformedURLException} that comes with the {@link URL}'s constructor, it is thrown in a * "shadowed" manner, wrapped in an {@link IllegalArgumentException} (which is a {@link RuntimeException}). * </p> * * @param spec URL spec to create a {@link URL} from * @return a new {@link URL} from the specified URL spec * @throws IllegalArgumentException if the specified URL spec is a malformed URL * * @see #createUrl(URL, String) * @see URL#URL(String) */ public static URL createUrl(final String spec) throws IllegalArgumentException { return createUrl(null, spec); } /** * Creates a new {@link URL} from the specified URL context and spec. * * <p> * Primary goal of this factory method is to suppress the {@link MalformedURLException} that comes with the {@link URL}'s constructor, it is thrown in a * "shadowed" manner, wrapped in an {@link IllegalArgumentException} (which is a {@link RuntimeException}). * </p> * * @param context URL context in which to interpret the URL spec * @param spec URL spec to create a {@link URL} from * @return a new {@link URL} from the specified URL spec * @throws IllegalArgumentException if the specified URL spec is a malformed URL * * @see #createUrl(String) * @see URL#URL(URL, String) */ public static URL createUrl(final URL context, final String spec) throws IllegalArgumentException { try { return new URL(context, spec); } catch (final MalformedURLException mue) { throw new RuntimeException("Malformed URL: " + spec, mue); } } }