Class UrlUtil


  • public final class UrlUtil
    extends Object
    Utility class for operations on URLs.
    • Method Detail

      • createUrl

        public static URL createUrl​(String str)
        Creates a URL by parsing the given string.

        This convenience factory method works as if by invoking the URL(String) constructor; any MalformedURLException thrown by the constructor is caught and wrapped in a new IllegalArgumentException object, which is then thrown.

        This method is provided for use in situations where it is known that the given string is a legal URL, for example for URL constants declared within a program, and so it would be considered a programming error for the string not to parse as such. The constructors, which throw MalformedURLException directly, should be used in situations where a URL is being constructed from user input or from some other source that may be prone to errors.

        Parameters:
        str - The string to be parsed into a URL
        Returns:
        The new URL
        Throws:
        IllegalArgumentException - if no protocol is specified, or an unknown protocol is found, or spec is null, or the parsed URL fails to comply with the specific syntax of the associated protocol.