Class StorageBodyFactory
- All Implemented Interfaces:
BodyFactory
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Charset
private final DecodeMonitor
private final StorageProvider
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a newBodyFactory
instance that uses the default storage provider for creating message bodies from input streams.StorageBodyFactory
(StorageProvider storageProvider, DecodeMonitor monitor) Creates a newBodyFactory
instance that uses the given storage provider for creating message bodies from input streams. -
Method Summary
Modifier and TypeMethodDescriptionCreates aBinaryBody
that holds the content of the given input stream.binaryBody
(Storage storage) Creates aBinaryBody
that holds the content of the givenStorage
.Returns theStorageProvider
thisBodyFactory
uses to create message bodies from input streams.textBody
(InputStream is) Creates aTextBody
that holds the content of the given input stream.textBody
(InputStream is, String mimeCharset) Creates aTextBody
that holds the content of the given input stream.Creates aTextBody
that holds the content of the given string.Creates aTextBody
that holds the content of the given string.private static Charset
toJavaCharset
(String mimeCharset, boolean forEncoding, DecodeMonitor monitor)
-
Field Details
-
FALLBACK_CHARSET
-
storageProvider
-
monitor
-
-
Constructor Details
-
StorageBodyFactory
public StorageBodyFactory()Creates a newBodyFactory
instance that uses the default storage provider for creating message bodies from input streams. -
StorageBodyFactory
Creates a newBodyFactory
instance that uses the given storage provider for creating message bodies from input streams.- Parameters:
storageProvider
- a storage provider ornull
to use the default one.
-
-
Method Details
-
getStorageProvider
Returns theStorageProvider
thisBodyFactory
uses to create message bodies from input streams.- Returns:
- a
StorageProvider
.
-
binaryBody
Creates aBinaryBody
that holds the content of the given input stream.- Specified by:
binaryBody
in interfaceBodyFactory
- Parameters:
is
- input stream to create a message body from.- Returns:
- a binary body.
- Throws:
IOException
- if an I/O error occurs.
-
binaryBody
Creates aBinaryBody
that holds the content of the givenStorage
.Note that the caller must not invoke
delete()
on the givenStorage
object after it has been passed to this method. Instead the message body created by this method takes care of deleting the storage when it gets disposed of (seeDisposable.dispose()
).- Parameters:
storage
- storage to create a message body from.- Returns:
- a binary body.
- Throws:
IOException
- if an I/O error occurs.
-
textBody
Creates aTextBody
that holds the content of the given input stream."us-ascii" is used to decode the byte content of the
Storage
into a character stream when callinggetReader()
on the returned object.- Parameters:
is
- input stream to create a message body from.- Returns:
- a text body.
- Throws:
IOException
- if an I/O error occurs.
-
textBody
Creates aTextBody
that holds the content of the given input stream.The charset corresponding to the given MIME charset name is used to decode the byte content of the input stream into a character stream when calling
getReader()
on the returned object. If the MIME charset has no corresponding Java charset or the Java charset cannot be used for decoding then "us-ascii" is used instead.- Specified by:
textBody
in interfaceBodyFactory
- Parameters:
is
- input stream to create a message body from.mimeCharset
- name of a MIME charset.- Returns:
- a text body.
- Throws:
IOException
- if an I/O error occurs.
-
textBody
Creates aTextBody
that holds the content of the givenStorage
."us-ascii" is used to decode the byte content of the
Storage
into a character stream when callinggetReader()
on the returned object.Note that the caller must not invoke
delete()
on the givenStorage
object after it has been passed to this method. Instead the message body created by this method takes care of deleting the storage when it gets disposed of (seeDisposable.dispose()
).- Parameters:
storage
- storage to create a message body from.- Returns:
- a text body.
- Throws:
IOException
- if an I/O error occurs.
-
textBody
Creates aTextBody
that holds the content of the givenStorage
.The charset corresponding to the given MIME charset name is used to decode the byte content of the
Storage
into a character stream when callinggetReader()
on the returned object. If the MIME charset has no corresponding Java charset or the Java charset cannot be used for decoding then "us-ascii" is used instead.Note that the caller must not invoke
delete()
on the givenStorage
object after it has been passed to this method. Instead the message body created by this method takes care of deleting the storage when it gets disposed of (seeDisposable.dispose()
).- Parameters:
storage
- storage to create a message body from.mimeCharset
- name of a MIME charset.- Returns:
- a text body.
- Throws:
IOException
- if an I/O error occurs.
-
textBody
Creates aTextBody
that holds the content of the given string."us-ascii" is used to encode the characters of the string into a byte stream when calling
writeTo(OutputStream)
on the returned object.- Parameters:
text
- text to create a message body from.- Returns:
- a text body.
-
textBody
Creates aTextBody
that holds the content of the given string.The charset corresponding to the given MIME charset name is used to encode the characters of the string into a byte stream when calling
writeTo(OutputStream)
on the returned object. If the MIME charset has no corresponding Java charset or the Java charset cannot be used for encoding then "us-ascii" is used instead.- Parameters:
text
- text to create a message body from.mimeCharset
- name of a MIME charset.- Returns:
- a text body.
-
toJavaCharset
private static Charset toJavaCharset(String mimeCharset, boolean forEncoding, DecodeMonitor monitor)
-