Package org.apache.james.mime4j.dom
Class SingleBody
- java.lang.Object
-
- org.apache.james.mime4j.dom.SingleBody
-
- All Implemented Interfaces:
Body,Disposable
- Direct Known Subclasses:
BinaryBody,TextBody
public abstract class SingleBody extends java.lang.Object implements Body
Abstract implementation of a single message body; that is, a body that does not contain (directly or indirectly) any other child bodies. It also provides the parent functionality required by bodies.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedSingleBody()Sole constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description SingleBodycopy()Returns a copy of thisSingleBody(optional operation).voiddispose()Subclasses should override this method if they have allocated resources that need to be freed explicitly (e.g.abstract java.io.InputStreamgetInputStream()Gets aInputStreamwhich reads the bytes of the body.EntitygetParent()Gets the parent of this body.voidsetParent(Entity parent)Sets the parent of this body.longsize()voidwriteTo(java.io.OutputStream out)Writes this single body to the given stream.
-
-
-
Field Detail
-
parent
private Entity parent
-
-
Method Detail
-
getParent
public Entity getParent()
Description copied from interface:BodyGets the parent of this body.- Specified by:
getParentin interfaceBody- Returns:
- the parent.
- See Also:
Body.getParent()
-
setParent
public void setParent(Entity parent)
Description copied from interface:BodySets the parent of this body.- Specified by:
setParentin interfaceBody- Parameters:
parent- the parent.- See Also:
Body.setParent(org.apache.james.mime4j.dom.Entity)
-
getInputStream
public abstract java.io.InputStream getInputStream() throws java.io.IOExceptionGets aInputStreamwhich reads the bytes of the body.- Returns:
- the stream, transfer decoded
- Throws:
java.io.IOException- on I/O errors.
-
writeTo
public void writeTo(java.io.OutputStream out) throws java.io.IOExceptionWrites this single body to the given stream. The default implementation copies the input stream obtained bygetInputStream()to the specified output stream. May be overwritten by a subclass to improve performance.- Parameters:
out- the stream to write to.- Throws:
java.io.IOException- in case of an I/O error
-
size
public long size() throws java.io.IOException- Throws:
java.io.IOException
-
copy
public SingleBody copy()
Returns a copy of thisSingleBody(optional operation).The general contract of this method is as follows:
- Invoking
getParent()on the copy returnsnull. That means that the copy is detached from the parent entity of thisSingleBody. The copy may get attached to a different entity later on. - The underlying content does not have to be copied. Instead it may be
shared between multiple copies of a
SingleBody. - If the underlying content is shared by multiple copies the implementation has to make sure that the content gets deleted when the last copy gets disposed of (and not before that).
This implementation always throws an
UnsupportedOperationException.- Returns:
- a copy of this
SingleBody. - Throws:
java.lang.UnsupportedOperationException- if thecopyoperation is not supported by this single body.
- Invoking
-
dispose
public void dispose()
Subclasses should override this method if they have allocated resources that need to be freed explicitly (e.g. cannot be simply reclaimed by the garbage collector). The default implementation of this method does nothing.- Specified by:
disposein interfaceDisposable- See Also:
Disposable.dispose()
-
-