replace Email's private base64 class with one from android-common

Convert all usages of com.android.email.codec.binary.Base64 to use
com.android.common.Base64 instead, except for Base64OutputStream
(which doesn't exist in android-common yet).

Change-Id: I339a1f451245138187080c7444fcabef8d13f8aa
This commit is contained in:
Doug Zongker 2010-02-08 13:04:03 -08:00
parent f3332ddac8
commit f44a40cda1
9 changed files with 58 additions and 60 deletions

View File

@ -24,6 +24,7 @@ LOCAL_SRC_FILES += \
src/com/android/email/service/IEmailServiceCallback.aidl
# EXCHANGE-REMOVE-SECTION-END
LOCAL_JAVA_STATIC_LIBRARIES := android-common
LOCAL_PACKAGE_NAME := Email

View File

@ -16,7 +16,7 @@
package com.android.email;
import com.android.email.provider.EmailContent;
import com.android.common.Base64;
import com.android.email.provider.EmailContent.Account;
import com.android.email.provider.EmailContent.AccountColumns;
import com.android.email.provider.EmailContent.HostAuth;
@ -25,9 +25,15 @@ import com.android.email.provider.EmailContent.Mailbox;
import com.android.email.provider.EmailContent.MailboxColumns;
import com.android.email.provider.EmailContent.Message;
import com.android.email.provider.EmailContent.MessageColumns;
import com.android.email.provider.EmailContent;
import android.content.ContentResolver;
import android.content.Context;
import android.content.res.TypedArray;
import android.database.Cursor;
import android.graphics.drawable.Drawable;
import android.text.Editable;
import android.widget.TextView;
import java.io.IOException;
import java.io.InputStream;
@ -35,14 +41,6 @@ import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.Date;
import com.android.email.codec.binary.Base64;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.text.Editable;
import android.widget.TextView;
public class Utility {
public final static String readInputStream(InputStream in, String encoding) throws IOException {
InputStreamReader reader = new InputStreamReader(in, encoding);
@ -91,7 +89,7 @@ public class Utility {
if (encoded == null) {
return null;
}
byte[] decoded = new Base64().decode(encoded.getBytes());
byte[] decoded = Base64.decode(encoded, Base64.DEFAULT);
return new String(decoded);
}
@ -99,8 +97,7 @@ public class Utility {
if (s == null) {
return s;
}
byte[] encoded = new Base64().encode(s.getBytes());
return new String(encoded);
return Base64.encodeToString(s.getBytes(), Base64.NO_WRAP);
}
public static boolean requiredFieldValid(TextView view) {

View File

@ -33,7 +33,7 @@ import java.math.BigInteger;
* @since 1.0-dev
* @version $Id$
*/
public class Base64 {
/* package */ class Base64 {
/**
* Chunk size per RFC 2045 section 6.8.
*

View File

@ -16,17 +16,16 @@
package com.android.email.mail.internet;
import com.android.common.Base64;
import com.android.email.mail.Body;
import com.android.email.mail.MessagingException;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import com.android.email.codec.binary.Base64;
import com.android.email.mail.Body;
import com.android.email.mail.MessagingException;
public class TextBody implements Body {
String mBody;
@ -36,7 +35,7 @@ public class TextBody implements Body {
public void writeTo(OutputStream out) throws IOException, MessagingException {
byte[] bytes = mBody.getBytes("UTF-8");
out.write(Base64.encodeBase64Chunked(bytes));
out.write(Base64.encode(bytes, Base64.CRLF));
}
/**

View File

@ -16,11 +16,11 @@
package com.android.email.mail.store;
import com.android.common.Base64;
import com.android.email.Email;
import com.android.email.Preferences;
import com.android.email.Utility;
import com.android.email.VendorPolicyLoader;
import com.android.email.codec.binary.Base64;
import com.android.email.mail.AuthenticationFailedException;
import com.android.email.mail.CertificateValidationException;
import com.android.email.mail.FetchProfile;
@ -257,7 +257,7 @@ public class ImapStore extends Store {
messageDigest.update(userName.getBytes());
messageDigest.update(devUID.getBytes());
byte[] uid = messageDigest.digest();
String hexUid = new String(new Base64().encode(uid));
String hexUid = Base64.encodeToString(uid, Base64.NO_WRAP);
id.append(" \"AGUID\" \"");
id.append(hexUid);
id.append('\"');

View File

@ -16,7 +16,7 @@
package com.android.email.mail.transport;
import com.android.email.codec.binary.Base64;
import com.android.common.Base64;
import com.android.email.codec.binary.Base64OutputStream;
import com.android.email.mail.Address;
import com.android.email.mail.MessagingException;
@ -323,6 +323,6 @@ public class Rfc822Output {
writer.write("\r\n");
byte[] bytes = text.getBytes("UTF-8");
writer.flush();
out.write(Base64.encodeBase64Chunked(bytes));
out.write(Base64.encode(bytes, Base64.CRLF));
}
}

View File

@ -16,8 +16,8 @@
package com.android.email.mail.transport;
import com.android.common.Base64;
import com.android.email.Email;
import com.android.email.codec.binary.Base64;
import com.android.email.mail.Address;
import com.android.email.mail.AuthenticationFailedException;
import com.android.email.mail.CertificateValidationException;
@ -304,9 +304,11 @@ public class SmtpSender extends Sender {
AuthenticationFailedException, IOException {
try {
executeSimpleCommand("AUTH LOGIN");
executeSensitiveCommand(new String(Base64.encodeBase64(username.getBytes())),
executeSensitiveCommand(
Base64.encodeToString(username.getBytes(), Base64.NO_WRAP),
"/username redacted/");
executeSensitiveCommand(new String(Base64.encodeBase64(password.getBytes())),
executeSensitiveCommand(
Base64.encodeToString(password.getBytes(), Base64.NO_WRAP),
"/password redacted/");
}
catch (MessagingException me) {
@ -320,7 +322,7 @@ public class SmtpSender extends Sender {
private void saslAuthPlain(String username, String password) throws MessagingException,
AuthenticationFailedException, IOException {
byte[] data = ("\000" + username + "\000" + password).getBytes();
data = new Base64().encode(data);
data = Base64.encode(data, Base64.NO_WRAP);
try {
executeSensitiveCommand("AUTH PLAIN " + new String(data), "AUTH PLAIN /redacted/");
}

View File

@ -17,9 +17,9 @@
package com.android.exchange;
import com.android.email.SecurityPolicy;
import com.android.common.Base64;
import com.android.email.SecurityPolicy.PolicySet;
import com.android.email.codec.binary.Base64;
import com.android.email.SecurityPolicy;
import com.android.email.mail.AuthenticationFailedException;
import com.android.email.mail.MessagingException;
import com.android.email.provider.EmailContent.Account;
@ -39,11 +39,11 @@ import com.android.exchange.adapter.ContactsSyncAdapter;
import com.android.exchange.adapter.EmailSyncAdapter;
import com.android.exchange.adapter.FolderSyncParser;
import com.android.exchange.adapter.MeetingResponseParser;
import com.android.exchange.adapter.Parser.EasParserException;
import com.android.exchange.adapter.PingParser;
import com.android.exchange.adapter.ProvisionParser;
import com.android.exchange.adapter.Serializer;
import com.android.exchange.adapter.Tags;
import com.android.exchange.adapter.Parser.EasParserException;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
@ -792,7 +792,7 @@ public class EasSyncService extends AbstractSyncService {
String safeUserName = URLEncoder.encode(mUserName);
if (mAuthString == null) {
String cs = mUserName + ':' + mPassword;
mAuthString = "Basic " + new String(Base64.encodeBase64(cs.getBytes()));
mAuthString = "Basic " + Base64.encodeToString(cs.getBytes(), Base64.NO_WRAP);
mCmdString = "&User=" + safeUserName + "&DeviceId=" + mDeviceId + "&DeviceType="
+ mDeviceType;
}

View File

@ -17,7 +17,7 @@
package com.android.exchange.adapter;
import com.android.email.codec.binary.Base64;
import com.android.common.Base64;
import com.android.email.provider.EmailContent.Mailbox;
import com.android.exchange.Eas;
import com.android.exchange.EasSyncService;
@ -1258,7 +1258,7 @@ public class ContactsSyncAdapter extends AbstractSyncAdapter {
RowBuilder builder = untypedRowBuilder(entity, Photo.CONTENT_ITEM_TYPE);
// We're always going to add this; it's not worth trying to figure out whether the
// picture is the same as the one stored.
byte[] pic = Base64.decodeBase64(photo.getBytes());
byte[] pic = Base64.decode(photo, Base64.DEFAULT);
builder.withValue(Photo.PHOTO, pic);
add(builder.build());
}
@ -1636,8 +1636,7 @@ public class ContactsSyncAdapter extends AbstractSyncAdapter {
private void sendPhoto(Serializer s, ContentValues cv) throws IOException {
if (cv.containsKey(Photo.PHOTO)) {
byte[] bytes = cv.getAsByteArray(Photo.PHOTO);
byte[] encodedBytes = Base64.encodeBase64(bytes);
String pic = new String(encodedBytes);
String pic = Base64.encodeToString(bytes, Base64.NO_WRAP);
s.data(Tags.CONTACTS_PICTURE, pic);
}
}