Class URL

  • All Implemented Interfaces:
    android.os.Parcelable

    public final class URL
    extends Object
    implements android.os.Parcelable
    Abstraction of URL. Unifies management of both absolutes and relatives URLs.
    • Field Detail

      • EMPTY

        public static final URL EMPTY
      • CREATOR

        public static final android.os.Parcelable.Creator<URL> CREATOR
    • Constructor Detail

      • URL

        public URL​(@NonNull
                   String value)
        Create a URL object with an absolute or relative URL. If value starts with '/' is considered relative, and will take URLs.SERVER as host with port.
        Parameters:
        value - String
    • Method Detail

      • getValue

        @NonNull
        public String getValue()
        Original value provided to de constructor
        Returns:
        constructor's value param
      • getLastTerm

        @NonNull
        public String getLastTerm()
        Returns las part of provided value, separated by '/'. Useful if the URL represents de location of a file, to obtain its name.
        Returns:
        string, empty if path is empty
      • isAbsolute

        public boolean isAbsolute()
        Return true if the value used to construct the URL doesn't start by '/', meaning it has a specific host. False if isRelative()
        Returns:
        true | false
      • isRelative

        public boolean isRelative()
        Return true if the value used to construct the URL starts by '/', meaning it has no specific host nor port. False if isAbsolute()
        Returns:
        true | false
      • port

        public int port()
                 throws MalformedURLException
        Gets the port number of this URL. If the port is not set, returns the port number of the protocol associated with this URL. If URL has no default port to this protocol, then -1 is returned.
        Returns:
        the port number
        Throws:
        MalformedURLException - exception thrown by URL when created
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • describeContents

        public int describeContents()
        Specified by:
        describeContents in interface android.os.Parcelable
      • writeToParcel

        public void writeToParcel​(android.os.Parcel dest,
                                  int flags)
        Specified by:
        writeToParcel in interface android.os.Parcelable