summaryrefslogtreecommitdiffstats
path: root/src/com/android/emailcommon/internet/TextBody.java
diff options
context:
space:
mode:
authorYing Wang <wangying@google.com>2011-03-01 14:52:05 -0800
committerYing Wang <wangying@google.com>2011-03-01 14:52:05 -0800
commita07f2ae0b18964aa15e218e8b6be8be24e5c9f46 (patch)
treed97e61c8fc0f0aa92e3f62eccd43e779dc2f7c90 /src/com/android/emailcommon/internet/TextBody.java
parent7c87bfc33aaf94e50e4be9ff0b838e4b3a3812f4 (diff)
downloadandroid_packages_apps_Email-a07f2ae0b18964aa15e218e8b6be8be24e5c9f46.tar.gz
android_packages_apps_Email-a07f2ae0b18964aa15e218e8b6be8be24e5c9f46.tar.bz2
android_packages_apps_Email-a07f2ae0b18964aa15e218e8b6be8be24e5c9f46.zip
Revert "Split out emailcommon/Android.mk"
This reverts commit c28bf353190eb576072a8fd2f98821424144876e.
Diffstat (limited to 'src/com/android/emailcommon/internet/TextBody.java')
-rw-r--r--src/com/android/emailcommon/internet/TextBody.java62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/com/android/emailcommon/internet/TextBody.java b/src/com/android/emailcommon/internet/TextBody.java
new file mode 100644
index 000000000..09c265c8e
--- /dev/null
+++ b/src/com/android/emailcommon/internet/TextBody.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.emailcommon.internet;
+
+import com.android.emailcommon.mail.Body;
+import com.android.emailcommon.mail.MessagingException;
+
+import android.util.Base64;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+
+public class TextBody implements Body {
+ String mBody;
+
+ public TextBody(String body) {
+ this.mBody = body;
+ }
+
+ public void writeTo(OutputStream out) throws IOException, MessagingException {
+ byte[] bytes = mBody.getBytes("UTF-8");
+ out.write(Base64.encode(bytes, Base64.CRLF));
+ }
+
+ /**
+ * 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 {
+ byte[] b = mBody.getBytes("UTF-8");
+ return new ByteArrayInputStream(b);
+ }
+ catch (UnsupportedEncodingException usee) {
+ return null;
+ }
+ }
+}