Class AttachmentCache

    • Constructor Detail

      • AttachmentCache

        public AttachmentCache​(AttachmentResolver resolver)
        Instantiates a cache with an AttachmentResolver that will be used to access attachment content registered with the add() method.
        Parameters:
        resolver - the resolver used to access attachment content registered with the add() 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: AttachmentResolver
        Returns a stream to read the content of the specified attachment.
        Specified by:
        getInputStream in interface AttachmentResolver
        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: AttachmentSizeProvider
        Returns the size of the logical attachment, i.e. the number of bytes of its content.
        Specified by:
        getSize in interface AttachmentSizeProvider
        Parameters:
        attachment - the attachment for which for size is to determine.
        Returns:
        the number of bytes of the attachment content, or 0 if the size is unknown.
      • dispose

        public void dispose()
        Deletes all temporary files used to store the registered attachments.
        Specified by:
        dispose in interface AttachmentResolver