1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-30 13:12:25 -05:00

Merge pull request #55 from andrewgaul/stringbuilder

Prefer StringBuilder over StringBuffer
This commit is contained in:
cketti 2011-10-06 09:04:43 -07:00
commit 2e2428b093
14 changed files with 36 additions and 36 deletions

View File

@ -380,7 +380,7 @@ public class Account implements BaseAccount {
} }
private String combineUuids(String[] uuids) { private String combineUuids(String[] uuids) {
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
for (int i = 0, length = uuids.length; i < length; i++) { for (int i = 0, length = uuids.length; i < length; i++) {
if (sb.length() > 0) { if (sb.length() > 0) {
sb.append(','); sb.append(',');

View File

@ -727,7 +727,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
private boolean setRecipients(TextView view, List<String> recipients) { private boolean setRecipients(TextView view, List<String> recipients) {
boolean recipientAdded = false; boolean recipientAdded = false;
if (recipients != null) { if (recipients != null) {
StringBuffer addressList = new StringBuffer(); StringBuilder addressList = new StringBuilder();
for (String recipient : recipients) { for (String recipient : recipients) {
addressList.append(recipient); addressList.append(recipient);
addressList.append(", "); addressList.append(", ");
@ -1964,7 +1964,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
mInReplyTo = message.getMessageId(); mInReplyTo = message.getMessageId();
if (message.getReferences() != null && message.getReferences().length > 0) { if (message.getReferences() != null && message.getReferences().length > 0) {
StringBuffer buffy = new StringBuffer(); StringBuilder buffy = new StringBuilder();
for (int i = 0; i < message.getReferences().length; i++) for (int i = 0; i < message.getReferences().length; i++)
buffy.append(message.getReferences()[i]); buffy.append(message.getReferences()[i]);

View File

@ -243,7 +243,7 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList
} }
mProgressBar.setIndeterminate(false); mProgressBar.setIndeterminate(false);
StringBuffer chainInfo = new StringBuffer(100); StringBuilder chainInfo = new StringBuilder(100);
MessageDigest sha1 = null; MessageDigest sha1 = null;
try { try {
sha1 = MessageDigest.getInstance("SHA-1"); sha1 = MessageDigest.getInstance("SHA-1");
@ -265,7 +265,7 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList
if (subjectAlternativeNames != null) { if (subjectAlternativeNames != null) {
// The list of SubjectAltNames may be very long // The list of SubjectAltNames may be very long
//TODO: localize this string //TODO: localize this string
StringBuffer altNamesText = new StringBuffer("Subject has " + subjectAlternativeNames.size() + " alternative names\n"); StringBuilder altNamesText = new StringBuilder("Subject has " + subjectAlternativeNames.size() + " alternative names\n");
// we need these for matching // we need these for matching
String storeURIHost = (Uri.parse(mAccount.getStoreUri())).getHost(); String storeURIHost = (Uri.parse(mAccount.getStoreUri())).getHost();

View File

@ -38,7 +38,7 @@ public class Utility {
public static String readInputStream(InputStream in, String encoding) throws IOException { public static String readInputStream(InputStream in, String encoding) throws IOException {
InputStreamReader reader = new InputStreamReader(in, encoding); InputStreamReader reader = new InputStreamReader(in, encoding);
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
int count; int count;
char[] buf = new char[512]; char[] buf = new char[512];
while ((count = reader.read(buf)) != -1) { while ((count = reader.read(buf)) != -1) {

View File

@ -179,7 +179,7 @@ public class Address {
if (addresses == null) { if (addresses == null) {
return null; return null;
} }
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
for (int i = 0; i < addresses.length; i++) { for (int i = 0; i < addresses.length; i++) {
sb.append(addresses[i].toString()); sb.append(addresses[i].toString());
if (i < addresses.length - 1) { if (i < addresses.length - 1) {
@ -201,7 +201,7 @@ public class Address {
if (addresses == null) { if (addresses == null) {
return null; return null;
} }
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
for (int i = 0; i < addresses.length; i++) { for (int i = 0; i < addresses.length; i++) {
sb.append(addresses[i].toEncodedString()); sb.append(addresses[i].toEncodedString());
if (i < addresses.length - 1) { if (i < addresses.length - 1) {

View File

@ -58,7 +58,7 @@ public class DecoderUtil {
/* /*
* Replace _ with =20 * Replace _ with =20
*/ */
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
for (int i = 0; i < encodedWord.length(); i++) { for (int i = 0; i < encodedWord.length(); i++) {
char c = encodedWord.charAt(i); char c = encodedWord.charAt(i);
if (c == '_') { if (c == '_') {

View File

@ -530,7 +530,7 @@ public class MimeMessage extends Message {
public void epilogue(InputStream is) throws IOException { public void epilogue(InputStream is) throws IOException {
expect(MimeMultipart.class); expect(MimeMultipart.class);
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
int b; int b;
while ((b = is.read()) != -1) { while ((b = is.read()) != -1) {
sb.append((char)b); sb.append((char)b);
@ -540,7 +540,7 @@ public class MimeMessage extends Message {
public void preamble(InputStream is) throws IOException { public void preamble(InputStream is) throws IOException {
expect(MimeMultipart.class); expect(MimeMultipart.class);
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
int b; int b;
while ((b = is.read()) != -1) { while ((b = is.read()) != -1) {
sb.append((char)b); sb.append((char)b);

View File

@ -37,7 +37,7 @@ public class MimeMultipart extends Multipart {
} }
public String generateBoundary() { public String generateBoundary() {
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
sb.append("----"); sb.append("----");
for (int i = 0; i < 30; i++) { for (int i = 0; i < 30; i++) {
sb.append(Integer.toString((int)(Math.random() * 35), 36)); sb.append(Integer.toString((int)(Math.random() * 35), 36));

View File

@ -281,7 +281,7 @@ public class ImapResponseParser {
private String parseQuoted() throws IOException { private String parseQuoted() throws IOException {
expect('"'); expect('"');
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
int ch; int ch;
boolean escape = false; boolean escape = false;
while ((ch = mIn.read()) != -1) { while ((ch = mIn.read()) != -1) {
@ -299,7 +299,7 @@ public class ImapResponseParser {
} }
private String readStringUntil(char end) throws IOException { private String readStringUntil(char end) throws IOException {
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
int ch; int ch;
while ((ch = mIn.read()) != -1) { while ((ch = mIn.read()) != -1) {
if (ch == end) { if (ch == end) {
@ -471,7 +471,7 @@ public class ImapResponseParser {
public String getAlertText() { public String getAlertText() {
if (size() > 1 && equalsIgnoreCase("[ALERT]", get(1))) { if (size() > 1 && equalsIgnoreCase("[ALERT]", get(1))) {
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
for (int i = 2, count = size(); i < count; i++) { for (int i = 2, count = size(); i < count; i++) {
sb.append(get(i).toString()); sb.append(get(i).toString());
sb.append(' '); sb.append(' ');

View File

@ -1417,7 +1417,7 @@ public class ImapStore extends Store {
// String key = (String)keyObj; // String key = (String)keyObj;
// if ("ALERT".equalsIgnoreCase(key)) // if ("ALERT".equalsIgnoreCase(key))
// { // {
// StringBuffer sb = new StringBuffer(); // StringBuilder sb = new StringBuilder();
// for (int i = 2, count = response.size(); i < count; i++) { // for (int i = 2, count = response.size(); i < count; i++) {
// sb.append(response.get(i).toString()); // sb.append(response.get(i).toString());
// sb.append(' '); // sb.append(' ');

View File

@ -844,7 +844,7 @@ public class LocalStore extends Store implements Serializable {
@Override @Override
public String toString() { public String toString() {
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
sb.append(command); sb.append(command);
sb.append(": "); sb.append(": ");
for (String argument : arguments) { for (String argument : arguments) {
@ -1788,7 +1788,7 @@ public class LocalStore extends Store implements Serializable {
try { try {
Map<Long, LocalMessage> popMessages = new HashMap<Long, LocalMessage>(); Map<Long, LocalMessage> popMessages = new HashMap<Long, LocalMessage>();
List<String> ids = new ArrayList<String>(); List<String> ids = new ArrayList<String>();
StringBuffer questions = new StringBuffer(); StringBuilder questions = new StringBuilder();
for (int i = 0; i < messages.size(); i++) { for (int i = 0; i < messages.size(); i++) {
if (i != 0) { if (i != 0) {
@ -2097,15 +2097,15 @@ public class LocalStore extends Store implements Serializable {
ArrayList<Part> attachments = new ArrayList<Part>(); ArrayList<Part> attachments = new ArrayList<Part>();
MimeUtility.collectParts(message, viewables, attachments); MimeUtility.collectParts(message, viewables, attachments);
StringBuffer sbHtml = new StringBuffer(); StringBuilder sbHtml = new StringBuilder();
StringBuffer sbText = new StringBuffer(); StringBuilder sbText = new StringBuilder();
for (Part viewable : viewables) { for (Part viewable : viewables) {
try { try {
String text = MimeUtility.getTextFromPart(viewable); String text = MimeUtility.getTextFromPart(viewable);
/* /*
* Small hack to make sure the string "null" doesn't end up * Small hack to make sure the string "null" doesn't end up
* in one of the StringBuffers. * in one of the StringBuilders.
*/ */
if (text == null) { if (text == null) {
text = ""; text = "";
@ -2210,8 +2210,8 @@ public class LocalStore extends Store implements Serializable {
MimeUtility.collectParts(message, viewables, attachments); MimeUtility.collectParts(message, viewables, attachments);
StringBuffer sbHtml = new StringBuffer(); StringBuilder sbHtml = new StringBuilder();
StringBuffer sbText = new StringBuffer(); StringBuilder sbText = new StringBuilder();
for (int i = 0, count = viewables.size(); i < count; i++) { for (int i = 0, count = viewables.size(); i < count; i++) {
Part viewable = viewables.get(i); Part viewable = viewables.get(i);
try { try {
@ -2219,7 +2219,7 @@ public class LocalStore extends Store implements Serializable {
/* /*
* Small hack to make sure the string "null" doesn't end up * Small hack to make sure the string "null" doesn't end up
* in one of the StringBuffers. * in one of the StringBuilders.
*/ */
if (text == null) { if (text == null) {
text = ""; text = "";

View File

@ -825,7 +825,7 @@ public class Pop3Store extends Store {
} }
private String readLine() throws IOException { private String readLine() throws IOException {
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
int d = mIn.read(); int d = mIn.read();
if (d == -1) { if (d == -1) {
throw new IOException("End of stream reached while trying to read line."); throw new IOException("End of stream reached while trying to read line.");

View File

@ -398,7 +398,7 @@ public class WebDavStore extends Store {
} }
private String getSpecialFoldersList() { private String getSpecialFoldersList() {
StringBuffer buffer = new StringBuffer(200); StringBuilder buffer = new StringBuilder(200);
buffer.append("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>"); buffer.append("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>");
buffer.append("<propfind xmlns=\"DAV:\">"); buffer.append("<propfind xmlns=\"DAV:\">");
buffer.append("<prop>"); buffer.append("<prop>");
@ -421,7 +421,7 @@ public class WebDavStore extends Store {
* WebDAV XML Request body retrieval functions * WebDAV XML Request body retrieval functions
*/ */
private String getFolderListXml() { private String getFolderListXml() {
StringBuffer buffer = new StringBuffer(200); StringBuilder buffer = new StringBuilder(200);
buffer.append("<?xml version='1.0' ?>"); buffer.append("<?xml version='1.0' ?>");
buffer.append("<a:searchrequest xmlns:a='DAV:'><a:sql>\r\n"); buffer.append("<a:searchrequest xmlns:a='DAV:'><a:sql>\r\n");
buffer.append("SELECT \"DAV:uid\", \"DAV:ishidden\"\r\n"); buffer.append("SELECT \"DAV:uid\", \"DAV:ishidden\"\r\n");
@ -432,7 +432,7 @@ public class WebDavStore extends Store {
} }
private String getMessageCountXml(String messageState) { private String getMessageCountXml(String messageState) {
StringBuffer buffer = new StringBuffer(200); StringBuilder buffer = new StringBuilder(200);
buffer.append("<?xml version='1.0' ?>"); buffer.append("<?xml version='1.0' ?>");
buffer.append("<a:searchrequest xmlns:a='DAV:'><a:sql>\r\n"); buffer.append("<a:searchrequest xmlns:a='DAV:'><a:sql>\r\n");
buffer.append("SELECT \"DAV:visiblecount\"\r\n"); buffer.append("SELECT \"DAV:visiblecount\"\r\n");
@ -445,7 +445,7 @@ public class WebDavStore extends Store {
} }
private String getMessageEnvelopeXml(String[] uids) { private String getMessageEnvelopeXml(String[] uids) {
StringBuffer buffer = new StringBuffer(200); StringBuilder buffer = new StringBuilder(200);
buffer.append("<?xml version='1.0' ?>"); buffer.append("<?xml version='1.0' ?>");
buffer.append("<a:searchrequest xmlns:a='DAV:'><a:sql>\r\n"); buffer.append("<a:searchrequest xmlns:a='DAV:'><a:sql>\r\n");
buffer.append("SELECT \"DAV:uid\", \"DAV:getcontentlength\","); buffer.append("SELECT \"DAV:uid\", \"DAV:getcontentlength\",");
@ -475,7 +475,7 @@ public class WebDavStore extends Store {
} }
private String getMessagesXml() { private String getMessagesXml() {
StringBuffer buffer = new StringBuffer(200); StringBuilder buffer = new StringBuilder(200);
buffer.append("<?xml version='1.0' ?>"); buffer.append("<?xml version='1.0' ?>");
buffer.append("<a:searchrequest xmlns:a='DAV:'><a:sql>\r\n"); buffer.append("<a:searchrequest xmlns:a='DAV:'><a:sql>\r\n");
buffer.append("SELECT \"DAV:uid\"\r\n"); buffer.append("SELECT \"DAV:uid\"\r\n");
@ -486,7 +486,7 @@ public class WebDavStore extends Store {
} }
private String getMessageUrlsXml(String[] uids) { private String getMessageUrlsXml(String[] uids) {
StringBuffer buffer = new StringBuffer(600); StringBuilder buffer = new StringBuilder(600);
buffer.append("<?xml version='1.0' ?>"); buffer.append("<?xml version='1.0' ?>");
buffer.append("<a:searchrequest xmlns:a='DAV:'><a:sql>\r\n"); buffer.append("<a:searchrequest xmlns:a='DAV:'><a:sql>\r\n");
buffer.append("SELECT \"urn:schemas:httpmail:read\", \"DAV:uid\"\r\n"); buffer.append("SELECT \"urn:schemas:httpmail:read\", \"DAV:uid\"\r\n");
@ -510,7 +510,7 @@ public class WebDavStore extends Store {
throw new MessagingException("Attempt to get flags on 0 length array for uids"); throw new MessagingException("Attempt to get flags on 0 length array for uids");
} }
StringBuffer buffer = new StringBuffer(200); StringBuilder buffer = new StringBuilder(200);
buffer.append("<?xml version='1.0' ?>"); buffer.append("<?xml version='1.0' ?>");
buffer.append("<a:searchrequest xmlns:a='DAV:'><a:sql>\r\n"); buffer.append("<a:searchrequest xmlns:a='DAV:'><a:sql>\r\n");
buffer.append("SELECT \"urn:schemas:httpmail:read\", \"DAV:uid\"\r\n"); buffer.append("SELECT \"urn:schemas:httpmail:read\", \"DAV:uid\"\r\n");
@ -529,7 +529,7 @@ public class WebDavStore extends Store {
} }
private String getMarkMessagesReadXml(String[] urls, boolean read) { private String getMarkMessagesReadXml(String[] urls, boolean read) {
StringBuffer buffer = new StringBuffer(600); StringBuilder buffer = new StringBuilder(600);
buffer.append("<?xml version='1.0' ?>\r\n"); buffer.append("<?xml version='1.0' ?>\r\n");
buffer.append("<a:propertyupdate xmlns:a='DAV:' xmlns:b='urn:schemas:httpmail:'>\r\n"); buffer.append("<a:propertyupdate xmlns:a='DAV:' xmlns:b='urn:schemas:httpmail:'>\r\n");
buffer.append("<a:target>\r\n"); buffer.append("<a:target>\r\n");
@ -553,7 +553,7 @@ public class WebDavStore extends Store {
private String getMoveOrCopyMessagesReadXml(String[] urls, boolean isMove) { private String getMoveOrCopyMessagesReadXml(String[] urls, boolean isMove) {
String action = (isMove ? "move" : "copy"); String action = (isMove ? "move" : "copy");
StringBuffer buffer = new StringBuffer(600); StringBuilder buffer = new StringBuilder(600);
buffer.append("<?xml version='1.0' ?>\r\n"); buffer.append("<?xml version='1.0' ?>\r\n");
buffer.append("<a:").append(action).append(" xmlns:a='DAV:' xmlns:b='urn:schemas:httpmail:'>\r\n"); buffer.append("<a:").append(action).append(" xmlns:a='DAV:' xmlns:b='urn:schemas:httpmail:'>\r\n");
buffer.append("<a:target>\r\n"); buffer.append("<a:target>\r\n");
@ -1488,7 +1488,7 @@ public class WebDavStore extends Store {
if (entity != null) { if (entity != null) {
InputStream istream = null; InputStream istream = null;
StringBuffer buffer = new StringBuffer(); StringBuilder buffer = new StringBuilder();
String tempText = ""; String tempText = "";
String resultText = ""; String resultText = "";
BufferedReader reader; BufferedReader reader;

View File

@ -429,7 +429,7 @@ public class SmtpTransport extends Transport {
} }
private String readLine() throws IOException { private String readLine() throws IOException {
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
int d; int d;
while ((d = mIn.read()) != -1) { while ((d = mIn.read()) != -1) {
if (((char)d) == '\r') { if (((char)d) == '\r') {