Package com.atlassian.bitbucket.avatar
Class DelegatingCacheableAvatarSupplier
java.lang.Object
com.atlassian.bitbucket.avatar.DelegatingCacheableAvatarSupplier
- All Implemented Interfaces:
AvatarSupplier
,CacheableAvatarSupplier
,InputSupplier<InputStream>
An
CacheableAvatarSupplier
implementation which delegates to an AvatarSupplier
, storing the avatar's
modification timestamp
separately. This class can be used to promote an ordinary
AvatarSupplier
to a CacheableAvatarSupplier
.-
Field Summary
Fields inherited from interface com.atlassian.bitbucket.avatar.CacheableAvatarSupplier
TIMESTAMP_ETERNAL, TIMESTAMP_UNKNOWN
-
Constructor Summary
ConstructorDescriptionConstructs a newDelegatingCacheableAvatarSupplier
with anunknown
timestamp.DelegatingCacheableAvatarSupplier
(AvatarSupplier supplier, long timestamp) Constructs a newDelegatingCacheableAvatarSupplier
with the providedtimestamp
. -
Method Summary
Modifier and TypeMethodDescriptionThe content type of the avatar, e.g., "image/png"long
The timestamp at which the avatar was last modified, in milliseconds.open()
Provides anInputStream
to read the avatar.
-
Constructor Details
-
DelegatingCacheableAvatarSupplier
Constructs a newDelegatingCacheableAvatarSupplier
with anunknown
timestamp.- Parameters:
supplier
- theAvatarSupplier
containing the avatar's content type andInputStream
- See Also:
-
DelegatingCacheableAvatarSupplier
Constructs a newDelegatingCacheableAvatarSupplier
with the providedtimestamp
.- Parameters:
supplier
- theAvatarSupplier
containing the avatar's content type andInputStream
timestamp
- the avatar's modification timestamp, which may beCacheableAvatarSupplier.TIMESTAMP_UNKNOWN
if no modification timestamp is known, orCacheableAvatarSupplier.TIMESTAMP_ETERNAL
if the avatar is unmodifiable
-
-
Method Details
-
getContentType
Description copied from interface:AvatarSupplier
The content type of the avatar, e.g., "image/png"- Specified by:
getContentType
in interfaceAvatarSupplier
- Returns:
- the string representing the content type
-
open
Description copied from interface:AvatarSupplier
Provides anInputStream
to read the avatar. Each call to this method will produce a new stream.- Specified by:
open
in interfaceAvatarSupplier
- Specified by:
open
in interfaceInputSupplier<InputStream>
- Returns:
- a stream from the avatar
- Throws:
IOException
- in case the avatar could not be opened or read
-
getTimestamp
public long getTimestamp()Description copied from interface:CacheableAvatarSupplier
The timestamp at which the avatar was last modified, in milliseconds.To account for differences in avatar repository implementations:
- If timestamp information is not available, implementations shall return
CacheableAvatarSupplier.TIMESTAMP_UNKNOWN
. Avatars without timestamps should not be cached, as it may not be possible to reliably detect updates. - If the avatar cannot be updated, implementations shall return
CacheableAvatarSupplier.TIMESTAMP_ETERNAL
. Such avatars may be cached more aggressively, as they cannot change.
- Specified by:
getTimestamp
in interfaceCacheableAvatarSupplier
- Returns:
- the avatar's modification timestamp in milliseconds, or
CacheableAvatarSupplier.TIMESTAMP_UNKNOWN
if no modification date is available, orCacheableAvatarSupplier.TIMESTAMP_ETERNAL
if the avatar is unmodifiable
- If timestamp information is not available, implementations shall return
-