com.xpn.xwiki.doc
Class XWikiAttachmentContent

java.lang.Object
  extended by com.xpn.xwiki.doc.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: 178556d8194eeca0db7c1a625b9060c8dd54b1c4 $

Constructor Summary
XWikiAttachmentContent()
          The default Constructor.
XWikiAttachmentContent(XWikiAttachment attachment)
          Constructor with associated attachment specified.
XWikiAttachmentContent(XWikiAttachmentContent original)
          Constructor which clones an existing XWikiAttachmentContent.
 
Method Summary
 Object clone()
           
 XWikiAttachment getAttachment()
           
 byte[] getContent()
          Deprecated. use getContentInputStream() instead
 InputStream getContentInputStream()
           
 OutputStream getContentOutputStream()
          Set the content of the attachment by writing to a provided OutputStream.
 long getId()
          This is used so that Hibernate will associate this content with the right attachment (metadata).
 int getSize()
           
 boolean isContentDirty()
          Is the content "dirty" meaning out of sync with the database.
 void setAttachment(XWikiAttachment attachment)
           
 void setContent(byte[] content)
          Deprecated. use setContent(java.io.InputStream, int) instead
 void setContent(InputStream is)
          Set the content of the attachment from an InputStream.
 void setContent(InputStream is, int len)
          Set the content of the attachment from a portion of an InputStream.
 void setContentDirty(boolean contentDirty)
          Set the content as "dirty" meaning out of sync with the database.
 void setId(long id)
          This function does nothing and exists only for Hibernate to be able to load a value which is not used.
 void setOwnerDocument(XWikiDocument ownerDocument)
          Set the owner document in order to propagate the content dirty flag.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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.

Method Detail

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.

clone

public Object clone()
Overrides:
clone in class Object

getContent

@Deprecated
public byte[] getContent()
Deprecated. use getContentInputStream() instead

Returns:
a byte array containing the binary content of the attachment.

setContent

@Deprecated
public void setContent(byte[] content)
Deprecated. use setContent(java.io.InputStream, int) instead

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.

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

public int getSize()
Returns:
the true size of the content of the attachment.
Since:
2.3M2

setOwnerDocument

public void setOwnerDocument(XWikiDocument ownerDocument)
Set the owner document in order to propagate the content dirty flag.

Parameters:
ownerDocument - the owner document.


Copyright © 2004-2013 XWiki. All Rights Reserved.