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
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.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncopy()
Returns a copy of thisSingleBody
(optional operation).void
dispose()
Subclasses should override this method if they have allocated resources that need to be freed explicitly (e.g.abstract InputStream
Gets aInputStream
which reads the bytes of the body.Gets the parent of this body.void
Sets the parent of this body.long
size()
void
writeTo
(OutputStream out) Writes this single body to the given stream.
-
Field Details
-
parent
-
-
Constructor Details
-
SingleBody
protected SingleBody()Sole constructor.
-
-
Method Details
-
getParent
Description copied from interface:Body
Gets the parent of this body. -
setParent
Description copied from interface:Body
Sets the parent of this body. -
getInputStream
Gets aInputStream
which reads the bytes of the body.- Returns:
- the stream, transfer decoded
- Throws:
IOException
- on I/O errors.
-
writeTo
Writes 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:
IOException
- in case of an I/O error
-
size
- Throws:
IOException
-
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:
UnsupportedOperationException
- if thecopy
operation 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:
dispose
in interfaceDisposable
- See Also:
-