Class URL

  • All Implemented Interfaces:
    java.io.Serializable

    public class URL
    extends java.lang.Object
    implements java.io.Serializable
    A parsed URL. Immutable.
    See Also:
    Serialized Form
    • Method Detail

      • scheme

        public java.lang.String scheme()
      • schemeData

        public java.lang.String schemeData()
      • username

        public java.lang.String username()
      • password

        public java.lang.String password()
      • userInfo

        public java.lang.String userInfo()
        Gets user info component (i.e. user:pass). This will return an empty string if neither user or password are set.
        Returns:
      • host

        public Host host()
      • authority

        public java.lang.String authority()
      • port

        public int port()
      • defaultPort

        public int defaultPort()
      • path

        public java.lang.String path()
      • pathSegments

        public java.util.List<java.lang.String> pathSegments()
      • query

        public java.lang.String query()
      • fragment

        public java.lang.String fragment()
      • file

        public java.lang.String file()
      • isHierarchical

        public boolean isHierarchical()
      • isOpaque

        public boolean isOpaque()
      • resolve

        public URL resolve​(java.lang.String input)
                    throws GalimatiasParseException
        Resolves a relative reference to an absolute URL. This is just a convenience method equivalent to:
         
          URL base = URL.parse("http://base.com");
          String relativeReference = "/foo/bar";
          URL absoluteURL = base.resolve(relativeReference);
         
         
        Parameters:
        input - Relative reference.
        Returns:
        Resolved absolute URL.
        Throws:
        GalimatiasParseException
      • relativize

        public java.lang.String relativize​(URL url)
        Returns a relative URL reference for the given URL. Behaves as @{link java.net.URI#relativize(URL)}.
        Parameters:
        url - Absolute URL.
        Returns:
        Relative reference.
      • toJavaURI

        public java.net.URI toJavaURI()
                               throws java.net.URISyntaxException
        Converts to URI. Conversion to URI will throw URISyntaxException if the URL contains unescaped unsafe characters as defined in RFC 2396. In order to prevent this, force RFC 2396 compliance when parsing the URL. For example: NOTE 1: This will not make distinction between no user and password and just empty user and no password.
                  
                      URL.parse("http://example.com").toJavaURI().toString() → "http://example.com"
                      URL.parse("http://@example.com").toJavaURI().toString() → "http://example.com"
                  
              
        TODO: Check if this exception can actually be thrown
        Returns:
        Throws:
        java.net.URISyntaxException
      • toJavaURL

        public java.net.URL toJavaURL()
                               throws java.net.MalformedURLException
        Converts to URL. This method is guaranteed to not throw an exception for URL protocols http, https, ftp, file and jar. It might or might not throw MalformedURLException for other URL protocols.
        Returns:
        Throws:
        java.net.MalformedURLException
      • fromJavaURI

        public static URL fromJavaURI​(java.net.URI uri)
        Construct a URL from a URI.
        Parameters:
        uri -
        Returns:
      • fromJavaURL

        public static URL fromJavaURL​(java.net.URL url)
        Construct a URL from a URL.
        Parameters:
        url -
        Returns:
      • toString

        public java.lang.String toString()
        Serializes the URL. Note that the "exclude fragment flag" (as in WHATWG standard) is not implemented.
        Overrides:
        toString in class java.lang.Object
      • toHumanString

        public java.lang.String toHumanString()
        Serializes the URL to a human-readable representation. That is, percent-decoded and with IDN domains in its Unicode representation.
        Returns:
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object