2008-11-01 17:32:06 -04:00
|
|
|
|
2008-12-16 18:34:01 -05:00
|
|
|
package com.android.email.mail.internet;
|
2008-11-01 17:32:06 -04:00
|
|
|
|
2008-12-16 18:34:01 -05:00
|
|
|
import com.android.email.codec.binary.Base64;
|
|
|
|
import com.android.email.mail.Body;
|
|
|
|
import com.android.email.mail.MessagingException;
|
2008-11-01 17:32:06 -04:00
|
|
|
|
2009-12-09 22:16:42 -05:00
|
|
|
import java.io.*;
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public class TextBody implements Body
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
String mBody;
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public TextBody(String body)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
this.mBody = body;
|
|
|
|
}
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public void writeTo(OutputStream out) throws IOException, MessagingException
|
|
|
|
{
|
|
|
|
if (mBody!=null)
|
|
|
|
{
|
2009-05-22 01:42:16 -04:00
|
|
|
byte[] bytes = mBody.getBytes("UTF-8");
|
|
|
|
out.write(Base64.encodeBase64Chunked(bytes));
|
|
|
|
}
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
2009-11-24 19:40:29 -05:00
|
|
|
|
2008-11-01 17:32:06 -04:00
|
|
|
/**
|
2009-11-24 19:40:29 -05:00
|
|
|
* Get the text of the body in it's unencoded format.
|
2008-11-01 17:32:06 -04:00
|
|
|
* @return
|
|
|
|
*/
|
2009-11-24 19:40:29 -05:00
|
|
|
public String getText()
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
return mBody;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an InputStream that reads this body's text in UTF-8 format.
|
|
|
|
*/
|
2009-11-24 19:40:29 -05:00
|
|
|
public InputStream getInputStream() throws MessagingException
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2009-05-22 01:42:16 -04:00
|
|
|
byte[] b;
|
2009-11-24 19:40:29 -05:00
|
|
|
if (mBody!=null)
|
|
|
|
{
|
2009-05-22 01:42:16 -04:00
|
|
|
b = mBody.getBytes("UTF-8");
|
|
|
|
}
|
2009-11-24 19:40:29 -05:00
|
|
|
else
|
|
|
|
{
|
2009-05-22 01:42:16 -04:00
|
|
|
b = new byte[0];
|
|
|
|
}
|
2008-11-01 17:32:06 -04:00
|
|
|
return new ByteArrayInputStream(b);
|
|
|
|
}
|
2009-11-24 19:40:29 -05:00
|
|
|
catch (UnsupportedEncodingException usee)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|