Messaging: Use StandardCharsets where possible
Change-Id: I45a19c47262116d34260e1957145580a7f97168e
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user