Class GlideUrl

  • All Implemented Interfaces:
    Key

    public class GlideUrl
    extends java.lang.Object
    implements Key
    A wrapper for strings representing http/https URLs responsible for ensuring URLs are properly escaped and avoiding unnecessary URL instantiations for loaders that require only string urls rather than URL objects.

    Users wishing to replace the class for handling URLs must register a factory using GlideUrl.

    To obtain a properly escaped URL, call toURL(). To obtain a properly escaped string URL, call toStringUrl(). To obtain a less safe, but less expensive to calculate cache key, call getCacheKey().

    This class can also optionally wrap Headers for convenience.

    • Constructor Summary

      Constructors 
      Constructor Description
      GlideUrl​(java.lang.String url)  
      GlideUrl​(java.lang.String url, Headers headers)  
      GlideUrl​(java.net.URL url)  
      GlideUrl​(java.net.URL url, Headers headers)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object o)
      For caching to work correctly, implementations must implement this method and Key.hashCode().
      java.lang.String getCacheKey()
      Returns an inexpensive to calculate String suitable for use as a disk cache key.
      java.util.Map<java.lang.String,​java.lang.String> getHeaders()
      Returns a non-null Map containing headers.
      int hashCode()
      For caching to work correctly, implementations must implement this method and Key.equals(Object).
      java.lang.String toString()  
      java.lang.String toStringUrl()
      Returns a properly escaped String url that can be used to make http/https requests.
      java.net.URL toURL()  
      void updateDiskCacheKey​(java.security.MessageDigest messageDigest)
      Adds all uniquely identifying information to the given digest.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • GlideUrl

        public GlideUrl​(java.net.URL url)
      • GlideUrl

        public GlideUrl​(java.lang.String url)
      • GlideUrl

        public GlideUrl​(java.net.URL url,
                        Headers headers)
      • GlideUrl

        public GlideUrl​(java.lang.String url,
                        Headers headers)
    • Method Detail

      • toURL

        public java.net.URL toURL()
                           throws java.net.MalformedURLException
        Throws:
        java.net.MalformedURLException
      • toStringUrl

        public java.lang.String toStringUrl()
        Returns a properly escaped String url that can be used to make http/https requests.
        See Also:
        toURL(), getCacheKey()
      • getHeaders

        public java.util.Map<java.lang.String,​java.lang.String> getHeaders()
        Returns a non-null Map containing headers.
      • getCacheKey

        public java.lang.String getCacheKey()
        Returns an inexpensive to calculate String suitable for use as a disk cache key.

        This method does not include headers.

        Unlike toStringUrl()} and toURL(), this method does not escape input.

      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • updateDiskCacheKey

        public void updateDiskCacheKey​(@NonNull
                                       java.security.MessageDigest messageDigest)
        Description copied from interface: Key
        Adds all uniquely identifying information to the given digest.

        Note - Using MessageDigest.reset() inside of this method will result in undefined behavior.

        Specified by:
        updateDiskCacheKey in interface Key
      • equals

        public boolean equals​(java.lang.Object o)
        Description copied from interface: Key
        For caching to work correctly, implementations must implement this method and Key.hashCode().
        Specified by:
        equals in interface Key
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Description copied from interface: Key
        For caching to work correctly, implementations must implement this method and Key.equals(Object).
        Specified by:
        hashCode in interface Key
        Overrides:
        hashCode in class java.lang.Object