Messaging: Use StandardCharsets where possible
Change-Id: I45a19c47262116d34260e1957145580a7f97168e
This commit is contained in:
@@ -33,7 +33,6 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.InetSocketAddress;
|
||||
@@ -41,6 +40,7 @@ import java.net.MalformedURLException;
|
||||
import java.net.ProtocolException;
|
||||
import java.net.Proxy;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
@@ -439,16 +439,8 @@ public class MmsHttpClient {
|
||||
nai = nai + naiSuffix;
|
||||
}
|
||||
byte[] encoded = null;
|
||||
try {
|
||||
encoded = Base64.encode(nai.getBytes("UTF-8"), Base64.NO_WRAP);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
encoded = Base64.encode(nai.getBytes(), Base64.NO_WRAP);
|
||||
}
|
||||
try {
|
||||
return new String(encoded, "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
return new String(encoded);
|
||||
}
|
||||
encoded = Base64.encode(nai.getBytes(StandardCharsets.UTF_8), Base64.NO_WRAP);
|
||||
return new String(encoded, StandardCharsets.UTF_8);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import androidx.annotation.NonNull;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
@@ -146,11 +147,7 @@ public class EncodedStringValue implements Cloneable {
|
||||
if (LOCAL_LOGV) {
|
||||
Log.v(TAG, e.getMessage(), e);
|
||||
}
|
||||
try {
|
||||
return new String(mData, CharacterSets.MIMENAME_ISO_8859_1);
|
||||
} catch (UnsupportedEncodingException e2) {
|
||||
return new String(mData); // system default encoding.
|
||||
}
|
||||
return new String(mData, StandardCharsets.ISO_8859_1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,8 +43,8 @@ import com.android.vcard.VCardEntry.PostalData;
|
||||
import com.android.vcard.VCardEntry.WebsiteData;
|
||||
import com.android.vcard.VCardProperty;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -200,11 +200,8 @@ public class VCardResourceEntry {
|
||||
}
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
final String address = formatAddress(postalData);
|
||||
try {
|
||||
intent.setData(Uri.parse("geo:0,0?q=" + URLEncoder.encode(address, "UTF-8")));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
intent = null;
|
||||
}
|
||||
intent.setData(Uri.parse("geo:0,0?q=" + URLEncoder.encode(address,
|
||||
StandardCharsets.UTF_8)));
|
||||
|
||||
retList.add(new VCardResourceEntryDestinationItem(address, type, intent));
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import androidx.annotation.NonNull;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
@@ -161,11 +162,7 @@ public class EncodedStringValue implements Cloneable {
|
||||
if (LOCAL_LOGV) {
|
||||
Log.v(TAG, e.getMessage(), e);
|
||||
}
|
||||
try {
|
||||
return new String(mData, CharacterSets.MIMENAME_ISO_8859_1);
|
||||
} catch (UnsupportedEncodingException exception) {
|
||||
return new String(mData); // system default encoding.
|
||||
}
|
||||
return new String(mData, StandardCharsets.ISO_8859_1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
@@ -1632,26 +1632,14 @@ public class PduPersister {
|
||||
* Wrap a byte[] into a String.
|
||||
*/
|
||||
public static String toIsoString(final byte[] bytes) {
|
||||
try {
|
||||
return new String(bytes, CharacterSets.MIMENAME_ISO_8859_1);
|
||||
} catch (final UnsupportedEncodingException e) {
|
||||
// Impossible to reach here!
|
||||
Log.e(TAG, "ISO_8859_1 must be supported!", e);
|
||||
return "";
|
||||
}
|
||||
return new String(bytes, StandardCharsets.ISO_8859_1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unpack a given String into a byte[].
|
||||
*/
|
||||
public static byte[] getBytes(final String data) {
|
||||
try {
|
||||
return data.getBytes(CharacterSets.MIMENAME_ISO_8859_1);
|
||||
} catch (final UnsupportedEncodingException e) {
|
||||
// Impossible to reach here!
|
||||
Log.e(TAG, "ISO_8859_1 must be supported!", e);
|
||||
return new byte[0];
|
||||
}
|
||||
return data.getBytes(StandardCharsets.ISO_8859_1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
* Copyright (C) 2024 The LineageOS Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -48,6 +49,7 @@ import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -959,11 +961,7 @@ public class DatabaseMessages {
|
||||
final String name = CharacterSets.getMimeName(charset);
|
||||
return new String(data, name);
|
||||
} catch (final UnsupportedEncodingException e) {
|
||||
try {
|
||||
return new String(data, CharacterSets.MIMENAME_ISO_8859_1);
|
||||
} catch (final UnsupportedEncodingException exception) {
|
||||
return new String(data); // system default encoding.
|
||||
}
|
||||
return new String(data, StandardCharsets.ISO_8859_1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
* Copyright (C) 2024 The LineageOS Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -35,8 +36,8 @@ import com.android.messaging.util.LogUtil;
|
||||
import com.android.messaging.util.UiUtils;
|
||||
import com.android.messaging.util.UriUtil;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -135,11 +136,7 @@ public class LaunchConversationActivity extends Activity implements
|
||||
final String[] params = urlStr.split("&");
|
||||
for (final String p : params) {
|
||||
if (p.startsWith("body=")) {
|
||||
try {
|
||||
return URLDecoder.decode(p.substring(5), "UTF-8");
|
||||
} catch (final UnsupportedEncodingException e) {
|
||||
// Invalid URL, ignore
|
||||
}
|
||||
return URLDecoder.decode(p.substring(5), StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -51,14 +51,14 @@ import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class ImageUtils {
|
||||
private static final String TAG = LogUtil.BUGLE_TAG;
|
||||
private static final int MAX_OOM_COUNT = 1;
|
||||
private static final byte[] GIF87_HEADER = "GIF87a".getBytes(Charset.forName("US-ASCII"));
|
||||
private static final byte[] GIF89_HEADER = "GIF89a".getBytes(Charset.forName("US-ASCII"));
|
||||
private static final byte[] GIF87_HEADER = "GIF87a".getBytes(StandardCharsets.US_ASCII);
|
||||
private static final byte[] GIF89_HEADER = "GIF89a".getBytes(StandardCharsets.US_ASCII);
|
||||
|
||||
// Used for drawBitmapWithCircleOnCanvas.
|
||||
// Default color is transparent for both circle background and stroke.
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2012 The Android Open Source Project
|
||||
* Copyright (C) 2024 The LineageOS Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,6 +24,7 @@ import java.io.InputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
class CountedDataInputStream extends FilterInputStream {
|
||||
|
||||
@@ -129,7 +131,7 @@ class CountedDataInputStream extends FilterInputStream {
|
||||
public String readString(int n) throws IOException {
|
||||
byte buf[] = new byte[n];
|
||||
readOrThrow(buf);
|
||||
return new String(buf, "UTF8");
|
||||
return new String(buf, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
public String readString(int n, Charset charset) throws IOException {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2012 The Android Open Source Project
|
||||
* Copyright (C) 2024 The LineageOS Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,6 +22,7 @@ import com.android.messaging.util.LogUtil;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -235,11 +237,11 @@ class ExifData {
|
||||
|
||||
try {
|
||||
if (Arrays.equals(code, USER_COMMENT_ASCII)) {
|
||||
return new String(buf, 8, buf.length - 8, "US-ASCII");
|
||||
return new String(buf, 8, buf.length - 8, StandardCharsets.US_ASCII);
|
||||
} else if (Arrays.equals(code, USER_COMMENT_JIS)) {
|
||||
return new String(buf, 8, buf.length - 8, "EUC-JP");
|
||||
} else if (Arrays.equals(code, USER_COMMENT_UNICODE)) {
|
||||
return new String(buf, 8, buf.length - 8, "UTF-16");
|
||||
return new String(buf, 8, buf.length - 8, StandardCharsets.UTF_16);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.TreeMap;
|
||||
|
||||
@@ -141,7 +142,7 @@ public class ExifParser {
|
||||
protected static final int TAG_SIZE = 12;
|
||||
protected static final int OFFSET_SIZE = 2;
|
||||
|
||||
private static final Charset US_ASCII = Charset.forName("US-ASCII");
|
||||
private static final Charset US_ASCII = StandardCharsets.US_ASCII;
|
||||
|
||||
protected static final int DEFAULT_IFD0_OFFSET = 8;
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ package com.android.messaging.util.exif;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
@@ -70,7 +71,7 @@ public class ExifTag {
|
||||
*/
|
||||
public static final short TYPE_RATIONAL = 10;
|
||||
|
||||
private static final Charset US_ASCII = Charset.forName("US-ASCII");
|
||||
private static final Charset US_ASCII = StandardCharsets.US_ASCII;
|
||||
private static final int TYPE_TO_SIZE_MAP[] = new int[11];
|
||||
private static final int UNSIGNED_SHORT_MAX = 65535;
|
||||
private static final long UNSIGNED_LONG_MAX = 4294967295L;
|
||||
|
||||
Reference in New Issue
Block a user