Package com.iizix.user
Class ProfilePictureInfo
java.lang.Object
com.iizix.user.ProfilePictureInfo
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
Modifier and TypeFieldDescriptionstatic Comparator<ProfilePictureInfo>
Sort instance to get the largest images first.Constructor Summary
ConstructorDescriptionProfilePictureInfo
(InputStream in, String mediaType) Constructor for image when size is unknown.ProfilePictureInfo
(String url, String mediaType) Constructor for image when size is unknown.ProfilePictureInfo
(String url, String mediaType, int width, int height) Constructor.ProfilePictureInfo
(URL url, String mediaType, int width, int height) Constructor.Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes a potentially open input stream of the image data.boolean
Checks if two objects are equal.int
Gets the height of the profile picture.getImageData
(StringBuilder mediaType) The image input stream, either from theurl
, or if the URL cannot be loaded without OAuth signatures.Gets the image type from the media type.Gets the media type, e.g.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.toString()
Gets a String.
Field Details
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
- Ifurl
ormediaType
isnull
.MalformedURLException
- If theurl
is malformed.URISyntaxException
- If theurl
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
- Ifurl
ormediaType
isnull
.MalformedURLException
- If theurl
is malformed.URISyntaxException
- If theurl
has a syntax error in its URI.
ProfilePictureInfo
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
- Ifurl
ormediaType
isnull
.
ProfilePictureInfo
Constructor for image when size is unknown.- Parameters:
in
- The input stream.mediaType
- The media type, e.g. 'image/jpeg'.- Throws:
NullPointerException
- Ifurl
ormediaType
isnull
.
Method Details
sortLargestFirst
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
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
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:
IOException
- If the input stream cannot be opened from theURL
(seegetURL()
.UnknownServiceException
- If the protocol does not support input.
getMediaType
Gets the media type, e.g. 'image/jpeg'.- Returns:
- The media type, never null.
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.equals
Checks if two objects are equal.toString
Gets a String.close
public void close()Closes a potentially open input stream of the image data.