public class BasicBodyFactory extends Object implements BodyFactory
Modifier and Type | Field and Description |
---|---|
static BasicBodyFactory |
INSTANCE |
Constructor and Description |
---|
BasicBodyFactory() |
BasicBodyFactory(boolean lenient) |
BasicBodyFactory(Charset defaultCharset) |
Modifier and Type | Method and Description |
---|---|
BinaryBody |
binaryBody(byte[] buf) |
BinaryBody |
binaryBody(InputStream is)
Creates a
BinaryBody that holds the content of the given input
stream. |
BinaryBody |
binaryBody(String content,
Charset charset) |
Charset |
getDefaultCharset() |
protected Charset |
resolveCharset(String mimeCharset)
Select the Charset for the given
mimeCharset string. |
TextBody |
textBody(byte[] content,
Charset charset) |
TextBody |
textBody(InputStream content,
String mimeCharset)
Creates a
TextBody that holds the content of the given input
stream. |
TextBody |
textBody(String text) |
TextBody |
textBody(String text,
Charset charset) |
TextBody |
textBody(String text,
String mimeCharset) |
public static final BasicBodyFactory INSTANCE
public BasicBodyFactory()
public BasicBodyFactory(Charset defaultCharset)
public BasicBodyFactory(boolean lenient)
public Charset getDefaultCharset()
protected Charset resolveCharset(String mimeCharset) throws UnsupportedEncodingException
Select the Charset for the given mimeCharset
string.
If you need support for non standard or invalid mimeCharset
specifications you might want to
create your own derived BodyFactory
extending BasicBodyFactory
and overriding this method as
suggested by MIME4J-218
The default behavior is lenient, invalid mimeCharset
specifications will return the
defaultCharset
.
mimeCharset
- - the string specification for a Charset e.g. "UTF-8"UnsupportedEncodingException
- if the mimeCharset is invalidpublic TextBody textBody(String text, String mimeCharset) throws UnsupportedEncodingException
UnsupportedEncodingException
public TextBody textBody(InputStream content, String mimeCharset) throws IOException
BodyFactory
TextBody
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.
textBody
in interface BodyFactory
content
- input stream to create a message body from.mimeCharset
- name of a MIME charset.IOException
- if an I/O error occurs.public BinaryBody binaryBody(String content, Charset charset)
public BinaryBody binaryBody(InputStream is) throws IOException
BodyFactory
BinaryBody
that holds the content of the given input
stream.binaryBody
in interface BodyFactory
is
- input stream to create a message body from.IOException
- if an I/O error occurs.public BinaryBody binaryBody(byte[] buf)
Copyright © 2004–2023 The Apache Software Foundation. All rights reserved.