Package com.iizix.user
Class ProfilePictureInfo
- java.lang.Object
- com.iizix.user.ProfilePictureInfo
public class ProfilePictureInfo extends java.lang.Object
Class holding profile picture information either in a URL or asInputStream
in case of OAuth 2.0 requirements to load the URL in an authenticated session.
Field Summary
Fields Modifier and Type Field Description static java.util.Comparator<ProfilePictureInfo>
LARGEST_FIRST
Sort instance to get the largest images first.
Constructor Summary
Constructors Constructor Description 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 Type Method Description void
close()
Closes a potentially open input stream of the image data.boolean
equals(java.lang.Object obj)
Checks if two objects are equal.int
getHeight()
Gets the height of the profile picture.java.io.InputStream
getImageData(java.lang.StringBuilder mediaType)
The image input stream, either from theurl
, or if the URL cannot be loaded without OAuth signatures.ImageType
getImageType()
Gets the image type from the media type.java.lang.String
getMediaType()
Gets the media type, e.g.java.net.URL
getURL()
Gets the URL to the profile picture.int
getWidth()
Gets the width of the profile picture.int
hashCode()
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.String
toString()
Gets a String.
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
- Ifurl
ormediaType
isnull
.java.net.MalformedURLException
- If theurl
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
- Ifurl
ormediaType
isnull
.java.net.MalformedURLException
- If theurl
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
- Ifurl
ormediaType
isnull
.
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
- Ifurl
ormediaType
isnull
.
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, ifnull
, sorting will not be done and a NullPointerException is NOT thrown.- Returns:
- The SAME INSTANCE as the input, sorting is done in-place,
null
ifimages
isnull
.
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
ifgetImageData(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 theurl
, 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 theURL
(seegetURL()
.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 supportedImageType
'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 classjava.lang.Object
- Returns:
- The hash code.
equals
public boolean equals(java.lang.Object obj)
Checks if two objects are equal.- Overrides:
equals
in classjava.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 classjava.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.