summaryrefslogtreecommitdiffstats
path: root/core/java
diff options
context:
space:
mode:
authorDaisuke Miyakawa <dmiyakawa@google.com>2009-11-16 17:11:25 +0900
committerDaisuke Miyakawa <dmiyakawa@google.com>2009-11-17 06:16:22 +0900
commit3d745c2b925ccc7c6591dbb3dfd21649782af991 (patch)
tree86e8abc02051362768544acb32cb343e08ccbce7 /core/java
parent9e807d7cc4e5deafc0744abd932e2b40e3f5e80b (diff)
downloadframeworks_base-3d745c2b925ccc7c6591dbb3dfd21649782af991.zip
frameworks_base-3d745c2b925ccc7c6591dbb3dfd21649782af991.tar.gz
frameworks_base-3d745c2b925ccc7c6591dbb3dfd21649782af991.tar.bz2
Make vCard composer use Base64 class for encoding String into bytes instead of using its own implementation.
Internal issue number: 2195990
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/pim/vcard/VCardComposer.java9
-rw-r--r--core/java/android/pim/vcard/VCardUtils.java50
2 files changed, 8 insertions, 51 deletions
diff --git a/core/java/android/pim/vcard/VCardComposer.java b/core/java/android/pim/vcard/VCardComposer.java
index 71f947c..d9f38bb 100644
--- a/core/java/android/pim/vcard/VCardComposer.java
+++ b/core/java/android/pim/vcard/VCardComposer.java
@@ -47,6 +47,8 @@ import android.text.format.Time;
import android.util.CharsetUtils;
import android.util.Log;
+import org.apache.commons.codec.binary.Base64;
+
import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -100,9 +102,8 @@ import java.util.Set;
* } </pre>
*/
public class VCardComposer {
- private static final String LOG_TAG = "vcard.VCardComposer";
+ private static final String LOG_TAG = "VCardComposer";
- // TODO: Should be configurable?
public static final int DEFAULT_PHONE_TYPE = Phone.TYPE_HOME;
public static final int DEFAULT_POSTAL_TYPE = StructuredPostal.TYPE_HOME;
public static final int DEFAULT_EMAIL_TYPE = Email.TYPE_OTHER;
@@ -1545,8 +1546,8 @@ public class VCardComposer {
Log.d(LOG_TAG, "Unknown photo type. Ignore.");
continue;
}
- final String photoString = VCardUtils.encodeBase64(data);
- if (photoString.length() > 0) {
+ final String photoString = new String(Base64.encodeBase64(data));
+ if (!TextUtils.isEmpty(photoString)) {
appendVCardPhotoLine(builder, photoString, photoType);
}
}
diff --git a/core/java/android/pim/vcard/VCardUtils.java b/core/java/android/pim/vcard/VCardUtils.java
index d1e1ec3..12a8e42 100644
--- a/core/java/android/pim/vcard/VCardUtils.java
+++ b/core/java/android/pim/vcard/VCardUtils.java
@@ -462,60 +462,16 @@ public class VCardUtils {
return true;
}
- // TODO: Replace wth the method in Base64 class.
- private static char PAD = '=';
- private static final char[] ENCODE64 = {
- 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
- 'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f',
- 'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v',
- 'w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/'
- };
-
- static public String encodeBase64(byte[] data) {
- if (data == null) {
- return "";
- }
-
- char[] charBuffer = new char[(data.length + 2) / 3 * 4];
- int position = 0;
- int _3byte = 0;
- for (int i=0; i<data.length-2; i+=3) {
- _3byte = ((data[i] & 0xFF) << 16) + ((data[i+1] & 0xFF) << 8) + (data[i+2] & 0xFF);
- charBuffer[position++] = ENCODE64[_3byte >> 18];
- charBuffer[position++] = ENCODE64[(_3byte >> 12) & 0x3F];
- charBuffer[position++] = ENCODE64[(_3byte >> 6) & 0x3F];
- charBuffer[position++] = ENCODE64[_3byte & 0x3F];
- }
- switch(data.length % 3) {
- case 1: // [111111][11 0000][0000 00][000000]
- _3byte = ((data[data.length-1] & 0xFF) << 16);
- charBuffer[position++] = ENCODE64[_3byte >> 18];
- charBuffer[position++] = ENCODE64[(_3byte >> 12) & 0x3F];
- charBuffer[position++] = PAD;
- charBuffer[position++] = PAD;
- break;
- case 2: // [111111][11 1111][1111 00][000000]
- _3byte = ((data[data.length-2] & 0xFF) << 16) + ((data[data.length-1] & 0xFF) << 8);
- charBuffer[position++] = ENCODE64[_3byte >> 18];
- charBuffer[position++] = ENCODE64[(_3byte >> 12) & 0x3F];
- charBuffer[position++] = ENCODE64[(_3byte >> 6) & 0x3F];
- charBuffer[position++] = PAD;
- break;
- }
-
- return new String(charBuffer);
- }
-
static public String toHalfWidthString(String orgString) {
if (TextUtils.isEmpty(orgString)) {
return null;
}
- StringBuilder builder = new StringBuilder();
- int length = orgString.length();
+ final StringBuilder builder = new StringBuilder();
+ final int length = orgString.length();
for (int i = 0; i < length; i++) {
// All Japanese character is able to be expressed by char.
// Do not need to use String#codepPointAt().
- char ch = orgString.charAt(i);
+ final char ch = orgString.charAt(i);
CharSequence halfWidthText = JapaneseUtils.tryGetHalfWidthText(ch);
if (halfWidthText != null) {
builder.append(halfWidthText);