From cb14cd9d780213c93e40f93b823e301d6e892d58 Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Mon, 31 Oct 2011 21:56:32 -0700 Subject: [PATCH] Prefer StringBuilder.append over String.concat Addresses FindBugs complaints. --- src/com/fsck/k9/activity/MessageCompose.java | 12 ++++----- src/com/fsck/k9/mail/store/ImapStore.java | 27 ++++++++++---------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/com/fsck/k9/activity/MessageCompose.java b/src/com/fsck/k9/activity/MessageCompose.java index 9ccd357c9..90b7f518a 100644 --- a/src/com/fsck/k9/activity/MessageCompose.java +++ b/src/com/fsck/k9/activity/MessageCompose.java @@ -1366,7 +1366,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc } if (mEncryptCheckbox.isChecked() && !mPgpData.hasEncryptionKeys()) { // key selection before encryption - String emails = ""; + StringBuilder emails = new StringBuilder(); Address[][] addresses = new Address[][] { getAddresses(mToView), getAddresses(mCcView), getAddresses(mBccView) @@ -1374,18 +1374,18 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc for (Address[] addressArray : addresses) { for (Address address : addressArray) { if (emails.length() != 0) { - emails += ","; + emails.append(','); } - emails += address.getAddress(); + emails.append(address.getAddress()); } } if (emails.length() != 0) { - emails += ","; + emails.append(','); } - emails += mIdentity.getEmail(); + emails.append(mIdentity.getEmail()); mPreventDraftSaving = true; - if (!mAccount.getCryptoProvider().selectEncryptionKeys(MessageCompose.this, emails, mPgpData)) { + if (!mAccount.getCryptoProvider().selectEncryptionKeys(MessageCompose.this, emails.toString(), mPgpData)) { mPreventDraftSaving = false; } return; diff --git a/src/com/fsck/k9/mail/store/ImapStore.java b/src/com/fsck/k9/mail/store/ImapStore.java index 4c22e812b..df9f3a4d1 100644 --- a/src/com/fsck/k9/mail/store/ImapStore.java +++ b/src/com/fsck/k9/mail/store/ImapStore.java @@ -1514,7 +1514,8 @@ public class ImapStore extends Store { /* * Set the content type with as much information as we know right now. */ - String contentType = String.format("%s", mimeType); + StringBuilder contentType = new StringBuilder(); + contentType.append(mimeType); if (bodyParams != null) { /* @@ -1522,13 +1523,13 @@ public class ImapStore extends Store { * of them. */ for (int i = 0, count = bodyParams.size(); i < count; i += 2) { - contentType += String.format(";\n %s=\"%s\"", - bodyParams.getString(i), - bodyParams.getString(i + 1)); + contentType.append(String.format(";\n %s=\"%s\"", + bodyParams.getString(i), + bodyParams.getString(i + 1))); } } - part.setHeader(MimeHeader.HEADER_CONTENT_TYPE, contentType); + part.setHeader(MimeHeader.HEADER_CONTENT_TYPE, contentType.toString()); // Extension items ImapList bodyDisposition = null; @@ -1542,11 +1543,11 @@ public class ImapStore extends Store { bodyDisposition = bs.getList(8); } - String contentDisposition = ""; + StringBuilder contentDisposition = new StringBuilder(); if (bodyDisposition != null && bodyDisposition.size() > 0) { if (!"NIL".equalsIgnoreCase(bodyDisposition.getString(0))) { - contentDisposition = bodyDisposition.getString(0).toLowerCase(Locale.US); + contentDisposition.append(bodyDisposition.getString(0).toLowerCase(Locale.US)); } if ((bodyDisposition.size() > 1) @@ -1557,22 +1558,22 @@ public class ImapStore extends Store { * about the attachment out. */ for (int i = 0, count = bodyDispositionParams.size(); i < count; i += 2) { - contentDisposition += String.format(";\n %s=\"%s\"", - bodyDispositionParams.getString(i).toLowerCase(Locale.US), - bodyDispositionParams.getString(i + 1)); + contentDisposition.append(String.format(";\n %s=\"%s\"", + bodyDispositionParams.getString(i).toLowerCase(Locale.US), + bodyDispositionParams.getString(i + 1))); } } } - if (MimeUtility.getHeaderParameter(contentDisposition, "size") == null) { - contentDisposition += String.format(";\n size=%d", size); + if (MimeUtility.getHeaderParameter(contentDisposition.toString(), "size") == null) { + contentDisposition.append(String.format(";\n size=%d", size)); } /* * Set the content disposition containing at least the size. Attachment * handling code will use this down the road. */ - part.setHeader(MimeHeader.HEADER_CONTENT_DISPOSITION, contentDisposition); + part.setHeader(MimeHeader.HEADER_CONTENT_DISPOSITION, contentDisposition.toString()); /*