Class AttachmentCache
- java.lang.Object
-
- com.sodius.mdw.metamodel.doors.richtext.AttachmentCache
-
- All Implemented Interfaces:
AttachmentResolver,AttachmentSizeProvider
public class AttachmentCache extends Object implements AttachmentResolver, AttachmentSizeProvider
Stores attachments into temporary files so they can be accessed in a second step.- Since:
- 3.4.0
-
-
Constructor Summary
Constructors Constructor Description AttachmentCache(AttachmentResolver resolver)Instantiates a cache with anAttachmentResolverthat will be used to access attachment content registered with theadd()method.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(Attachment attachment)Stores in a temporary file the specified attachment content.voidaddAll(Collection<Attachment> attachments)Stores in temporary files the specified attachments content.voiddispose()Deletes all temporary files used to store the registered attachments.InputStreamgetInputStream(Attachment attachment)Returns a stream to read the content of the specified attachment.longgetSize(Attachment attachment)Returns the size of the logical attachment, i.e.
-
-
-
Constructor Detail
-
AttachmentCache
public AttachmentCache(AttachmentResolver resolver)
Instantiates a cache with anAttachmentResolverthat will be used to access attachment content registered with theadd()method.- Parameters:
resolver- the resolver used to access attachment content registered with theadd()method.
-
-
Method Detail
-
add
public void add(Attachment attachment) throws IOException
Stores in a temporary file the specified attachment content.- Parameters:
attachment- an attachment whose content is to be stored.- Throws:
IOException- if the attachment content cannot be read.
-
addAll
public void addAll(Collection<Attachment> attachments) throws IOException
Stores in temporary files the specified attachments content.- Parameters:
attachments- attachments whose content is to be stored.- Throws:
IOException- if an attachment content cannot be read.
-
getInputStream
public InputStream getInputStream(Attachment attachment) throws IOException
Description copied from interface:AttachmentResolverReturns a stream to read the content of the specified attachment.- Specified by:
getInputStreamin interfaceAttachmentResolver- Parameters:
attachment- the logical attachment for which content is to be accessed.- Returns:
- a stream to access the content of the attachment
- Throws:
IOException- an exception if the physical content of the attachment cannot be found or if it failed to be accessed.
-
getSize
public long getSize(Attachment attachment)
Description copied from interface:AttachmentSizeProviderReturns the size of the logical attachment, i.e. the number of bytes of its content.- Specified by:
getSizein interfaceAttachmentSizeProvider- Parameters:
attachment- the attachment for which for size is to determine.- Returns:
- the number of bytes of the attachment content, or
0if the size is unknown.
-
dispose
public void dispose()
Deletes all temporary files used to store the registered attachments.- Specified by:
disposein interfaceAttachmentResolver
-
-