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
|
|
|
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.OutputStream;
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
public class TextBody implements Body {
|
|
|
|
String mBody;
|
|
|
|
|
|
|
|
public TextBody(String body) {
|
|
|
|
this.mBody = body;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void writeTo(OutputStream out) throws IOException, MessagingException {
|
2009-05-22 01:42:16 -04:00
|
|
|
if (mBody!=null) {
|
|
|
|
byte[] bytes = mBody.getBytes("UTF-8");
|
|
|
|
out.write(Base64.encodeBase64Chunked(bytes));
|
|
|
|
}
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the text of the body in it's unencoded format.
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public String getText() {
|
|
|
|
return mBody;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an InputStream that reads this body's text in UTF-8 format.
|
|
|
|
*/
|
|
|
|
public InputStream getInputStream() throws MessagingException {
|
|
|
|
try {
|
2009-05-22 01:42:16 -04:00
|
|
|
byte[] b;
|
|
|
|
if (mBody!=null) {
|
|
|
|
b = mBody.getBytes("UTF-8");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
b = new byte[0];
|
|
|
|
}
|
2008-11-01 17:32:06 -04:00
|
|
|
return new ByteArrayInputStream(b);
|
|
|
|
}
|
|
|
|
catch (UnsupportedEncodingException usee) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|