Class XWikiAttachmentContent

  • All Implemented Interfaces:
    Cloneable

    public class XWikiAttachmentContent
    extends Object
    implements Cloneable
    The content of an attachment. Objects of this class hold the actual content which will be downloaded when a user downloads an attachment.
    Version:
    $Id: 829a973cd120751a03350f62601cc3b34e1d3e1b $
    • Constructor Detail

      • XWikiAttachmentContent

        public XWikiAttachmentContent​(XWikiAttachmentContent original)
        Constructor which clones an existing XWikiAttachmentContent. Used by clone().
        Parameters:
        original - the XWikiAttachmentContent to clone.
        Since:
        2.6M1
      • XWikiAttachmentContent

        public XWikiAttachmentContent​(XWikiAttachment attachment)
        Constructor with associated attachment specified.
        Parameters:
        attachment - the attachment which this is the content for.
      • XWikiAttachmentContent

        public XWikiAttachmentContent()
        The default Constructor. For creating content which will be associated with an attachment later.
      • XWikiAttachmentContent

        protected XWikiAttachmentContent​(XWikiAttachment attachment,
                                         org.apache.commons.fileupload.FileItem f)
    • Method Detail

      • getFileItem

        protected org.apache.commons.fileupload.FileItem getFileItem()
        Returns:
        the underlying storage file.
        Since:
        5.2M1
      • getId

        public long getId()
        This is used so that Hibernate will associate this content with the right attachment (metadata).
        Returns:
        the id of the attachment (metadata) which this content is associated with.
      • setId

        public void setId​(long id)
        This function does nothing and exists only for Hibernate to be able to load a value which is not used.
        Parameters:
        id - is ignored.
      • getContent

        @Deprecated
        public byte[] getContent()
        Deprecated.
        Returns:
        a byte array containing the binary content of the attachment.
      • setContent

        @Deprecated
        public void setContent​(byte[] content)
        Deprecated.
        Set the content from a byte array.
        Parameters:
        content - a byte array containing the binary data of the attachment
      • getAttachment

        public XWikiAttachment getAttachment()
        Returns:
        which attachment (Metadata) this content belongs to.
      • setAttachment

        public void setAttachment​(XWikiAttachment attachment)
        Parameters:
        attachment - which attachment (metadata) this content is to be associated with.
      • isContentDirty

        public boolean isContentDirty()
        Is the content "dirty" meaning out of sync with the database.
        Returns:
        true if the content is out of sync with the database and in need of saving.
      • setContentDirty

        public void setContentDirty​(boolean contentDirty)
        Set the content as "dirty" meaning out of sync with the database.
        Parameters:
        contentDirty - if true then the content is regarded as out of sync with the database and in need of saving, otherwise it's considered saved.
      • exists

        public boolean exists()
        Returns:
        true of the content of this attachment still exist in the store
        Since:
        13.8RC1, 13.4.4, 12.10.10
      • getContentInputStream

        public InputStream getContentInputStream()
        Returns:
        an InputStream to read the binary content of this attachment.
        Since:
        2.3M2
      • getContentOutputStream

        public OutputStream getContentOutputStream()
        Set the content of the attachment by writing to a provided OutputStream. Content is *not* appended, this method clears the content and creates new content. If you want to append content, you can call getContentInputStream() and copy the content of that into the provided OutputStream. Before closing this OutputStream the content will remain the old content prior to the change.
        Returns:
        an OutputStream into which the caller can set the content of the attachments.
        Since:
        4.2M3
      • setContent

        public void setContent​(InputStream is,
                               int len)
                        throws IOException
        Set the content of the attachment from a portion of an InputStream.
        Parameters:
        is - the input stream that will be read
        len - the number of bytes to read from the beginning of the stream
        Throws:
        IOException - when an error occurs during streaming operation
        Since:
        2.3M2
      • setContent

        public void setContent​(InputStream is)
                        throws IOException
        Set the content of the attachment from an InputStream.
        Parameters:
        is - the input stream that will be read
        Throws:
        IOException - when an error occurs during streaming operation
        Since:
        2.6M1
      • getSize

        @Deprecated
        public int getSize()
        Deprecated.
        since 9.0RC1, use getLongSize() instead
        Returns:
        the true size of the content of the attachment.
        Since:
        2.3M2
      • getLongSize

        public long getLongSize()
        Returns:
        the true size of the content of the attachment. -1 if the size is unknown.
        Since:
        9.0RC1
      • setOwnerDocument

        public void setOwnerDocument​(XWikiDocument ownerDocument)
        Set the owner document in order to propagate the content dirty flag.
        Parameters:
        ownerDocument - the owner document.
      • dispose

        @Unstable
        public void dispose()
        Delete the temporary file item created to hold the content of the attachment. This method only performs the deletion if its content is dirty, its purpose is mainly to allow cleaning temporary attachments.
        Since:
        14.3RC1