mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-27 11:42:16 -05:00
remove some try-catch cruft
This commit is contained in:
parent
46d083bcad
commit
afb65d5ad7
@ -19,7 +19,7 @@ import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.Provider;
|
||||
import java.security.SecureRandom;
|
||||
@ -284,10 +284,7 @@ public final class PRNGFixes {
|
||||
if (serial != null) {
|
||||
result.append(serial);
|
||||
}
|
||||
try {
|
||||
return result.toString().getBytes("UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("UTF-8 encoding not supported");
|
||||
}
|
||||
|
||||
return result.toString().getBytes(Charset.forName("UTF-8"));
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.text.DateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -1890,13 +1891,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
|
||||
private InputStream getOpenPgpInputStream() {
|
||||
String text = buildText(false).getText();
|
||||
|
||||
InputStream is = null;
|
||||
try {
|
||||
is = new ByteArrayInputStream(text.getBytes("UTF-8"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
Log.e(K9.LOG_TAG, "UnsupportedEncodingException.", e);
|
||||
}
|
||||
return is;
|
||||
return new ByteArrayInputStream(text.getBytes(Charset.forName("UTF-8")));
|
||||
}
|
||||
|
||||
private void executeOpenPgpMethod(Intent intent) {
|
||||
|
@ -20,7 +20,7 @@ import com.fsck.k9.mail.filter.Base64;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
@ -189,8 +189,8 @@ public class Utility {
|
||||
* hundreds of times in places that slow down the UI, so it helps.
|
||||
*/
|
||||
public static String fastUrlDecode(String s) {
|
||||
try {
|
||||
byte[] bytes = s.getBytes("UTF-8");
|
||||
|
||||
byte[] bytes = s.getBytes(Charset.forName("UTF-8"));
|
||||
byte ch;
|
||||
int length = 0;
|
||||
for (int i = 0, count = bytes.length; i < count; i++) {
|
||||
@ -213,10 +213,8 @@ public class Utility {
|
||||
}
|
||||
length++;
|
||||
}
|
||||
return new String(bytes, 0, length, "UTF-8");
|
||||
} catch (UnsupportedEncodingException uee) {
|
||||
return null;
|
||||
}
|
||||
return new String(bytes, 0, length, Charset.forName("UTF-8"));
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -17,8 +17,8 @@
|
||||
|
||||
package com.fsck.k9.mail.filter;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.math.BigInteger;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
/**
|
||||
* Provides Base64 encoding and decoding as defined by RFC 2045.
|
||||
@ -225,12 +225,8 @@ public class Base64 {
|
||||
}
|
||||
this.decodeSize = encodeSize - 1;
|
||||
if (containsBase64Byte(lineSeparator)) {
|
||||
String sep;
|
||||
try {
|
||||
sep = new String(lineSeparator, "UTF-8");
|
||||
} catch (UnsupportedEncodingException uee) {
|
||||
sep = new String(lineSeparator);
|
||||
}
|
||||
String sep = new String(lineSeparator, Charset.forName("UTF-8"));
|
||||
|
||||
throw new IllegalArgumentException("lineSeperator must not contain base64 characters: [" + sep + "]");
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,8 @@ import com.fsck.k9.mail.Message;
|
||||
import com.fsck.k9.mail.MessagingException;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import org.apache.james.mime4j.codec.Base64InputStream;
|
||||
import org.apache.james.mime4j.codec.QuotedPrintableInputStream;
|
||||
import org.apache.james.mime4j.util.CharsetUtil;
|
||||
@ -30,12 +31,7 @@ public class DecoderUtil {
|
||||
* @return the decoded string.
|
||||
*/
|
||||
private static String decodeB(String encodedWord, String charset) {
|
||||
byte[] bytes;
|
||||
try {
|
||||
bytes = encodedWord.getBytes("US-ASCII");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
return null;
|
||||
}
|
||||
byte[] bytes = encodedWord.getBytes(Charset.forName("US-ASCII"));
|
||||
|
||||
Base64InputStream is = new Base64InputStream(new ByteArrayInputStream(bytes));
|
||||
try {
|
||||
@ -68,12 +64,7 @@ public class DecoderUtil {
|
||||
}
|
||||
}
|
||||
|
||||
byte[] bytes;
|
||||
try {
|
||||
bytes = sb.toString().getBytes("US-ASCII");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
return null;
|
||||
}
|
||||
byte[] bytes = sb.toString().getBytes(Charset.forName("US-ASCII"));
|
||||
|
||||
QuotedPrintableInputStream is = new QuotedPrintableInputStream(new ByteArrayInputStream(bytes));
|
||||
try {
|
||||
|
@ -757,18 +757,10 @@ public class ImapStore extends Store {
|
||||
}
|
||||
|
||||
private String encodeFolderName(String name) {
|
||||
try {
|
||||
ByteBuffer bb = mModifiedUtf7Charset.encode(name);
|
||||
byte[] b = new byte[bb.limit()];
|
||||
bb.get(b);
|
||||
return new String(b, "US-ASCII");
|
||||
} catch (UnsupportedEncodingException uee) {
|
||||
/*
|
||||
* The only thing that can throw this is getBytes("US-ASCII") and if US-ASCII doesn't
|
||||
* exist we're totally screwed.
|
||||
*/
|
||||
throw new RuntimeException("Unable to encode folder name: " + name, uee);
|
||||
}
|
||||
return new String(b, Charset.forName("US-ASCII"));
|
||||
}
|
||||
|
||||
private String decodeFolderName(String name) throws CharacterCodingException {
|
||||
@ -776,18 +768,11 @@ public class ImapStore extends Store {
|
||||
* Convert the encoded name to US-ASCII, then pass it through the modified UTF-7
|
||||
* decoder and return the Unicode String.
|
||||
*/
|
||||
try {
|
||||
// Make sure the decoder throws an exception if it encounters an invalid encoding.
|
||||
CharsetDecoder decoder = mModifiedUtf7Charset.newDecoder().onMalformedInput(CodingErrorAction.REPORT);
|
||||
CharBuffer cb = decoder.decode(ByteBuffer.wrap(name.getBytes("US-ASCII")));
|
||||
CharBuffer cb = decoder.decode(ByteBuffer.wrap(name.getBytes(Charset.forName("US-ASCII"))));
|
||||
return cb.toString();
|
||||
} catch (UnsupportedEncodingException uee) {
|
||||
/*
|
||||
* The only thing that can throw this is getBytes("US-ASCII") and if US-ASCII doesn't
|
||||
* exist we're totally screwed.
|
||||
*/
|
||||
throw new RuntimeException("Unable to decode folder name: " + name, uee);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -5,6 +5,7 @@ import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Fragment;
|
||||
@ -279,12 +280,7 @@ public class MessageOpenPgpView extends LinearLayout {
|
||||
String accName = OpenPgpApiHelper.buildAccountName(identity);
|
||||
intent.putExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME, accName);
|
||||
|
||||
InputStream is = null;
|
||||
try {
|
||||
is = new ByteArrayInputStream(mData.getBytes("UTF-8"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
Log.e(K9.LOG_TAG, "UnsupportedEncodingException.", e);
|
||||
}
|
||||
InputStream is = new ByteArrayInputStream(mData.getBytes(Charset.forName("UTF-8")));
|
||||
final ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
|
||||
DecryptVerifyCallback callback = new DecryptVerifyCallback(os, REQUEST_CODE_DECRYPT_VERIFY);
|
||||
|
Loading…
Reference in New Issue
Block a user