Class ProfilePictureInfo


  • public class ProfilePictureInfo
    extends java.lang.Object
    Class holding profile picture information either in a URL or as InputStream in case of OAuth 2.0 requirements to load the URL in an authenticated session.
    • Field Summary

      Fields 
      Modifier and TypeFieldDescription
      static java.util.Comparator<ProfilePictureInfo>LARGEST_FIRST
      Sort instance to get the largest images first.
    • Constructor Summary

      Constructors 
      ConstructorDescription
      ProfilePictureInfo​(java.io.InputStream in, java.lang.String mediaType)
      Constructor for image when size is unknown.
      ProfilePictureInfo​(java.lang.String url, java.lang.String mediaType)
      Constructor for image when size is unknown.
      ProfilePictureInfo​(java.lang.String url, java.lang.String mediaType, int width, int height)
      Constructor.
      ProfilePictureInfo​(java.net.URL url, java.lang.String mediaType, int width, int height)
      Constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and TypeMethodDescription
      voidclose()
      Closes a potentially open input stream of the image data.
      booleanequals​(java.lang.Object obj)
      Checks if two objects are equal.
      intgetHeight()
      Gets the height of the profile picture.
      java.io.InputStreamgetImageData​(java.lang.StringBuilder mediaType)
      The image input stream, either from the url, or if the URL cannot be loaded without OAuth signatures.
      ImageTypegetImageType()
      Gets the image type from the media type.
      java.lang.StringgetMediaType()
      Gets the media type, e.g.
      java.net.URLgetURL()
      Gets the URL to the profile picture.
      intgetWidth()
      Gets the width of the profile picture.
      inthashCode()
      Gets the hash code of this instance.
      static ProfilePictureInfo[]sortLargestFirst​(ProfilePictureInfo[] images)
      Sorts the array of ProfilePictureInfo's so that the largest ones comes first.
      java.lang.StringtoString()
      Gets a String.
      • Methods inherited from class java.lang.Object

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

      • LARGEST_FIRST

        public static java.util.Comparator<ProfilePictureInfo> LARGEST_FIRST
        Sort instance to get the largest images first. Images without size are always last.
    • Constructor Detail

      • ProfilePictureInfo

        public ProfilePictureInfo​(java.lang.String url,
                                  java.lang.String mediaType)
                           throws java.net.MalformedURLException
        Constructor for image when size is unknown.
        Parameters:
        url - The URL to the profile picture.
        mediaType - The media type, e.g. 'image/jpeg'.
        Throws:
        java.lang.NullPointerException - If url or mediaType is null.
        java.net.MalformedURLException - If the url is malformed.
      • ProfilePictureInfo

        public ProfilePictureInfo​(java.lang.String url,
                                  java.lang.String mediaType,
                                  int width,
                                  int height)
                           throws java.net.MalformedURLException
        Constructor.
        Parameters:
        url - The URL to the profile picture.
        mediaType - The media type, e.g. 'image/jpeg'.
        width - The width of the image, zero/negative if unknown.
        height - The height of the image, zero/negative if unknown.
        Throws:
        java.lang.NullPointerException - If url or mediaType is null.
        java.net.MalformedURLException - If the url is malformed.
      • ProfilePictureInfo

        public ProfilePictureInfo​(java.net.URL url,
                                  java.lang.String mediaType,
                                  int width,
                                  int height)
        Constructor.
        Parameters:
        url - The URL to the profile picture.
        mediaType - The media type, e.g. 'image/jpeg'.
        width - The width of the image, zero/negative if unknown.
        height - The height of the image, zero/negative if unknown.
        Throws:
        java.lang.NullPointerException - If url or mediaType is null.
      • ProfilePictureInfo

        public ProfilePictureInfo​(java.io.InputStream in,
                                  java.lang.String mediaType)
        Constructor for image when size is unknown.
        Parameters:
        in - The input stream.
        mediaType - The media type, e.g. 'image/jpeg'.
        Throws:
        java.lang.NullPointerException - If url or mediaType is null.
    • Method Detail

      • sortLargestFirst

        public static ProfilePictureInfo[] sortLargestFirst​(ProfilePictureInfo[] images)
        Sorts the array of ProfilePictureInfo's so that the largest ones comes first. Images without size are always last.
        Parameters:
        images - The array of ProfilePictureInfo's, if null, sorting will not be done and a NullPointerException is NOT thrown.
        Returns:
        The SAME INSTANCE as the input, sorting is done in-place, null if images is null.
      • getURL

        public java.net.URL getURL()
        Gets the URL to the profile picture.
        Returns:
        The URL, e.g. "https://..cdn.com/dms/image/..?e=..", or null if getImageData(StringBuilder) should be used instead (i.e. URL can only be retrieved with OAuth).
      • getImageData

        public java.io.InputStream getImageData​(java.lang.StringBuilder mediaType)
                                         throws java.io.IOException
        The image input stream, either from the url, or if the URL cannot be loaded without OAuth signatures.

        Note: the URL connection is configured for the proxy settings of the environment.

        Returns:
        The image input stream.
        Throws:
        java.io.IOException - If the input stream cannot be opened from the URL (see getURL().
        java.net.UnknownServiceException - If the protocol does not support input.
      • getMediaType

        public java.lang.String getMediaType()
        Gets the media type, e.g. 'image/jpeg'.
        Returns:
        The media type, never null.
      • getImageType

        public ImageType getImageType()
        Gets the image type from the media type.
        Returns:
        The image type or ImageType.ALL_IMAGES if the media type doesn't many any of the supported ImageType's.
      • getWidth

        public int getWidth()
        Gets the width of the profile picture.

        If either width or height is unknown, -1 is returned.

        Returns:
        The width, or -1 if unknown (never zero).
      • getHeight

        public int getHeight()
        Gets the height of the profile picture.

        If either width or height is unknown, -1 is returned.

        Returns:
        The height, or -1 if unknown (never zero).
      • hashCode

        public int hashCode()
        Gets the hash code of this instance.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        The hash code.
      • equals

        public boolean equals​(java.lang.Object obj)
        Checks if two objects are equal.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        obj - The other object to compare with.
        Returns:
        The equality flag.
      • toString

        public java.lang.String toString()
        Gets a String.
        Overrides:
        toString in class java.lang.Object
        Returns:
        The string as "[[width x height,]mediaType,url]" or "[[width x height,]mediaType,<inputStream>]"
      • close

        public void close()
        Closes a potentially open input stream of the image data.