Class ProfilePictureInfo

java.lang.Object
com.iizix.user.ProfilePictureInfo

public class ProfilePictureInfo extends 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 Details

    • LARGEST_FIRST

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

    • ProfilePictureInfo

      public ProfilePictureInfo(String url, String mediaType) throws MalformedURLException, URISyntaxException
      Constructor for image when size is unknown.
      Parameters:
      url - The URL to the profile picture.
      mediaType - The media type, e.g. 'image/jpeg'.
      Throws:
      NullPointerException - If url or mediaType is null.
      MalformedURLException - If the url is malformed.
      URISyntaxException - If the url has a syntax error in its URI.
    • ProfilePictureInfo

      public ProfilePictureInfo(String url, String mediaType, int width, int height) throws MalformedURLException, URISyntaxException
      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:
      NullPointerException - If url or mediaType is null.
      MalformedURLException - If the url is malformed.
      URISyntaxException - If the url has a syntax error in its URI.
    • ProfilePictureInfo

      public ProfilePictureInfo(URL url, 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:
      NullPointerException - If url or mediaType is null.
    • ProfilePictureInfo

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

    • 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 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 InputStream getImageData(StringBuilder mediaType) throws 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:
      IOException - If the input stream cannot be opened from the URL (see getURL().
      UnknownServiceException - If the protocol does not support input.
    • getMediaType

      public 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 Object
      Returns:
      The hash code.
    • equals

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

      public String toString()
      Gets a String.
      Overrides:
      toString in class 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.