public class AttachmentCache extends Object implements AttachmentResolver, AttachmentSizeProvider
Constructor and Description |
---|
AttachmentCache(AttachmentResolver resolver)
Instantiates a cache with an
AttachmentResolver that will be used to access attachment content registered with the
add() method. |
Modifier and Type | Method and Description |
---|---|
void |
add(Attachment attachment)
Stores in a temporary file the specified attachment content.
|
void |
addAll(Collection<Attachment> attachments)
Stores in temporary files the specified attachments content.
|
void |
dispose()
Deletes all temporary files used to store the registered attachments.
|
InputStream |
getInputStream(Attachment attachment)
Returns a stream to read the content of the specified attachment.
|
long |
getSize(Attachment attachment)
Returns the size of the logical attachment, i.e.
|
public AttachmentCache(AttachmentResolver resolver)
AttachmentResolver
that will be used to access attachment content registered with the
add()
method.resolver
- the resolver used to access attachment content registered with the add()
method.public void add(Attachment attachment) throws IOException
attachment
- an attachment whose content is to be stored.IOException
- if the attachment content cannot be read.public void addAll(Collection<Attachment> attachments) throws IOException
attachments
- attachments whose content is to be stored.IOException
- if an attachment content cannot be read.public InputStream getInputStream(Attachment attachment) throws IOException
AttachmentResolver
getInputStream
in interface AttachmentResolver
attachment
- the logical attachment for which content is to be accessed.IOException
- an exception if the physical content of the attachment cannot be found
or if it failed to be accessed.public long getSize(Attachment attachment)
AttachmentSizeProvider
getSize
in interface AttachmentSizeProvider
attachment
- the attachment for which for size is to determine.0
if the size is unknown.public void dispose()
dispose
in interface AttachmentResolver