Class StorageBodyFactory
- java.lang.Object
-
- org.apache.james.mime4j.storage.StorageBodyFactory
-
- All Implemented Interfaces:
BodyFactory
public class StorageBodyFactory extends Object implements BodyFactory
Factory for creating message bodies.
-
-
Constructor Summary
Constructors Constructor Description StorageBodyFactory()Creates a newBodyFactoryinstance that uses the default storage provider for creating message bodies from input streams.StorageBodyFactory(StorageProvider storageProvider, DecodeMonitor monitor)Creates a newBodyFactoryinstance that uses the given storage provider for creating message bodies from input streams.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BinaryBodybinaryBody(InputStream is)Creates aBinaryBodythat holds the content of the given input stream.BinaryBodybinaryBody(Storage storage)Creates aBinaryBodythat holds the content of the givenStorage.StorageProvidergetStorageProvider()Returns theStorageProviderthisBodyFactoryuses to create message bodies from input streams.TextBodytextBody(InputStream is)Creates aTextBodythat holds the content of the given input stream.TextBodytextBody(InputStream is, String mimeCharset)Creates aTextBodythat holds the content of the given input stream.TextBodytextBody(String text)Creates aTextBodythat holds the content of the given string.TextBodytextBody(String text, String mimeCharset)Creates aTextBodythat holds the content of the given string.TextBodytextBody(Storage storage)TextBodytextBody(Storage storage, String mimeCharset)
-
-
-
Constructor Detail
-
StorageBodyFactory
public StorageBodyFactory()
Creates a newBodyFactoryinstance that uses the default storage provider for creating message bodies from input streams.
-
StorageBodyFactory
public StorageBodyFactory(StorageProvider storageProvider, DecodeMonitor monitor)
Creates a newBodyFactoryinstance that uses the given storage provider for creating message bodies from input streams.- Parameters:
storageProvider- a storage provider ornullto use the default one.
-
-
Method Detail
-
getStorageProvider
public StorageProvider getStorageProvider()
Returns theStorageProviderthisBodyFactoryuses to create message bodies from input streams.- Returns:
- a
StorageProvider.
-
binaryBody
public BinaryBody binaryBody(InputStream is) throws IOException
Creates aBinaryBodythat holds the content of the given input stream.- Specified by:
binaryBodyin interfaceBodyFactory- Parameters:
is- input stream to create a message body from.- Returns:
- a binary body.
- Throws:
IOException- if an I/O error occurs.
-
binaryBody
public BinaryBody binaryBody(Storage storage) throws IOException
Creates aBinaryBodythat holds the content of the givenStorage.Note that the caller must not invoke
delete()on the givenStorageobject 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
public TextBody textBody(InputStream is) throws IOException
Creates aTextBodythat holds the content of the given input stream."us-ascii" is used to decode the byte content of the
Storageinto 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
public TextBody textBody(InputStream is, String mimeCharset) throws IOException
Creates aTextBodythat 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:
textBodyin 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
public TextBody textBody(Storage storage) throws IOException
Creates aTextBodythat holds the content of the givenStorage."us-ascii" is used to decode the byte content of the
Storageinto a character stream when callinggetReader()on the returned object.Note that the caller must not invoke
delete()on the givenStorageobject 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
public TextBody textBody(Storage storage, String mimeCharset) throws IOException
Creates aTextBodythat holds the content of the givenStorage.The charset corresponding to the given MIME charset name is used to decode the byte content of the
Storageinto 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 givenStorageobject 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
public TextBody textBody(String text)
Creates aTextBodythat 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
public TextBody textBody(String text, String mimeCharset)
Creates aTextBodythat 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.
-
-