Warnings and finals
Change-Id: Ifbc64087e2d623ed91c4be45fb7414d8b7803ee4
diff --git a/src/com/android/emailcommon/internet/MimeMessage.java b/src/com/android/emailcommon/internet/MimeMessage.java
index aa275c5..9300f6d 100644
--- a/src/com/android/emailcommon/internet/MimeMessage.java
+++ b/src/com/android/emailcommon/internet/MimeMessage.java
@@ -96,12 +96,12 @@
* @return a long, locally-generated message-ID value
*/
private static String generateMessageId() {
- StringBuffer sb = new StringBuffer();
+ final StringBuilder sb = new StringBuilder();
sb.append("<");
for (int i = 0; i < 24; i++) {
// We'll use a 5-bit range (0..31)
- int value = sRandom.nextInt() & 31;
- char c = "0123456789abcdefghijklmnopqrstuv".charAt(value);
+ final int value = sRandom.nextInt() & 31;
+ final char c = "0123456789abcdefghijklmnopqrstuv".charAt(value);
sb.append(c);
}
sb.append(".");
@@ -113,7 +113,7 @@
/**
* Parse the given InputStream using Apache Mime4J to build a MimeMessage.
*
- * @param in
+ * @param in InputStream providing message content
* @throws IOException
* @throws MessagingException
*/
@@ -134,20 +134,20 @@
mSentDate = null;
mBody = null;
- MimeStreamParser parser = new MimeStreamParser();
+ final MimeStreamParser parser = new MimeStreamParser();
parser.setContentHandler(new MimeMessageBuilder());
return parser;
}
protected void parse(InputStream in) throws IOException, MessagingException {
- MimeStreamParser parser = init();
+ final MimeStreamParser parser = init();
parser.parse(new EOLConvertingInputStream(in));
mComplete = !parser.getPrematureEof();
}
public void parse(InputStream in, EOLConvertingInputStream.Callback callback)
throws IOException, MessagingException {
- MimeStreamParser parser = init();
+ final MimeStreamParser parser = init();
parser.parse(new EOLConvertingInputStream(in, getSize(), callback));
mComplete = !parser.getPrematureEof();
}
@@ -178,7 +178,7 @@
// TODO: We should make it more clear what exceptions can be thrown here,
// and whether they reflect a normal or error condition.
} catch (Exception e) {
-
+ LogUtils.v(LogUtils.TAG, "Message missing Date header");
}
}
if (mSentDate == null) {
@@ -190,7 +190,7 @@
// TODO: We should make it more clear what exceptions can be thrown here,
// and whether they reflect a normal or error condition.
} catch (Exception e) {
-
+ LogUtils.v(LogUtils.TAG, "Message also missing Delivery-Date header");
}
}
return mSentDate;
@@ -204,7 +204,7 @@
@Override
public String getContentType() throws MessagingException {
- String contentType = getFirstHeader(MimeHeader.HEADER_CONTENT_TYPE);
+ final String contentType = getFirstHeader(MimeHeader.HEADER_CONTENT_TYPE);
if (contentType == null) {
return "text/plain";
} else {
@@ -214,17 +214,12 @@
@Override
public String getDisposition() throws MessagingException {
- String contentDisposition = getFirstHeader(MimeHeader.HEADER_CONTENT_DISPOSITION);
- if (contentDisposition == null) {
- return null;
- } else {
- return contentDisposition;
- }
+ return getFirstHeader(MimeHeader.HEADER_CONTENT_DISPOSITION);
}
@Override
public String getContentId() throws MessagingException {
- String contentId = getFirstHeader(MimeHeader.HEADER_CONTENT_ID);
+ final String contentId = getFirstHeader(MimeHeader.HEADER_CONTENT_ID);
if (contentId == null) {
return null;
} else {
@@ -406,7 +401,7 @@
public void setBody(Body body) throws MessagingException {
this.mBody = body;
if (body instanceof Multipart) {
- Multipart multipart = ((Multipart)body);
+ final Multipart multipart = ((Multipart)body);
multipart.setParent(this);
setHeader(MimeHeader.HEADER_CONTENT_TYPE, multipart.getContentType());
setHeader("MIME-Version", "1.0");
@@ -494,8 +489,8 @@
mExtendedHeader = null;
} else {
mExtendedHeader = new MimeHeader();
- for (String header : END_OF_LINE.split(headers)) {
- String[] tokens = header.split(":", 2);
+ for (final String header : END_OF_LINE.split(headers)) {
+ final String[] tokens = header.split(":", 2);
if (tokens.length != 2) {
throw new MessagingException("Illegal extended headers: " + headers);
}
@@ -523,7 +518,7 @@
*/
@Override
public void writeTo(OutputStream out) throws IOException, MessagingException {
- BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out), 1024);
+ final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out), 1024);
// Force creation of local message-id
getMessageId();
getMimeHeaders().writeTo(out);
@@ -561,7 +556,7 @@
} else {
expect(Part.class);
try {
- MimeMessage m = new MimeMessage();
+ final MimeMessage m = new MimeMessage();
((Part)stack.peek()).setBody(m);
stack.push(m);
} catch (MessagingException me) {
@@ -585,7 +580,7 @@
public void field(String fieldData) {
expect(Part.class);
try {
- String[] tokens = fieldData.split(":", 2);
+ final String[] tokens = fieldData.split(":", 2);
((Part)stack.peek()).addHeader(tokens[0], tokens[1].trim());
} catch (MessagingException me) {
throw new Error(me);
@@ -601,9 +596,9 @@
public void startMultipart(BodyDescriptor bd) {
expect(Part.class);
- Part e = (Part)stack.peek();
+ final Part e = (Part)stack.peek();
try {
- MimeMultipart multiPart = new MimeMultipart(e.getContentType());
+ final MimeMultipart multiPart = new MimeMultipart(e.getContentType());
e.setBody(multiPart);
stack.push(multiPart);
} catch (MessagingException me) {
@@ -614,7 +609,7 @@
@Override
public void body(BodyDescriptor bd, InputStream in) throws IOException {
expect(Part.class);
- Body body = MimeUtility.decodeBody(in, bd.getTransferEncoding());
+ final Body body = MimeUtility.decodeBody(in, bd.getTransferEncoding());
try {
((Part)stack.peek()).setBody(body);
} catch (MessagingException me) {
@@ -632,7 +627,7 @@
expect(MimeMultipart.class);
try {
- MimeBodyPart bodyPart = new MimeBodyPart();
+ final MimeBodyPart bodyPart = new MimeBodyPart();
((MimeMultipart)stack.peek()).addBodyPart(bodyPart);
stack.push(bodyPart);
} catch (MessagingException me) {
@@ -649,18 +644,19 @@
@Override
public void epilogue(InputStream is) throws IOException {
expect(MimeMultipart.class);
- StringBuffer sb = new StringBuffer();
+ final StringBuilder sb = new StringBuilder();
int b;
while ((b = is.read()) != -1) {
sb.append((char)b);
}
+ // TODO: why is this commented out?
// ((Multipart) stack.peek()).setEpilogue(sb.toString());
}
@Override
public void preamble(InputStream is) throws IOException {
expect(MimeMultipart.class);
- StringBuffer sb = new StringBuffer();
+ final StringBuilder sb = new StringBuilder();
int b;
while ((b = is.read()) != -1) {
sb.append((char)b);