Merge "Switch frameworks/base over from @hidden Charsets to public StandardCharsets."

This commit is contained in:
Elliott Hughes
2013-06-28 23:31:35 +00:00
committed by Gerrit Code Review
10 changed files with 39 additions and 39 deletions

View File

@ -25,7 +25,7 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.charset.Charsets; import java.nio.charset.StandardCharsets;
import java.util.AbstractList; import java.util.AbstractList;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -1688,7 +1688,7 @@ public abstract class Uri implements Parcelable, Comparable<Uri> {
return ""; return "";
} else { } else {
String encodedValue = query.substring(separator + 1, end); String encodedValue = query.substring(separator + 1, end);
return UriCodec.decode(encodedValue, true, Charsets.UTF_8, false); return UriCodec.decode(encodedValue, true, StandardCharsets.UTF_8, false);
} }
} }
@ -1927,7 +1927,7 @@ public abstract class Uri implements Parcelable, Comparable<Uri> {
if (s == null) { if (s == null) {
return null; return null;
} }
return UriCodec.decode(s, false, Charsets.UTF_8, false); return UriCodec.decode(s, false, StandardCharsets.UTF_8, false);
} }
/** /**

View File

@ -7,7 +7,7 @@ import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.ByteOrder; import java.nio.ByteOrder;
import java.nio.charset.Charsets; import java.nio.charset.StandardCharsets;
import java.nio.ShortBuffer; import java.nio.ShortBuffer;
import java.util.ArrayList; import java.util.ArrayList;
@ -540,7 +540,7 @@ abstract class DhcpPacket {
private static String readAsciiString(ByteBuffer buf, int byteCount) { private static String readAsciiString(ByteBuffer buf, int byteCount) {
byte[] bytes = new byte[byteCount]; byte[] bytes = new byte[byteCount];
buf.get(bytes); buf.get(bytes);
return new String(bytes, 0, bytes.length, Charsets.US_ASCII); return new String(bytes, 0, bytes.length, StandardCharsets.US_ASCII);
} }
/** /**

View File

@ -22,7 +22,7 @@ import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import java.nio.BufferUnderflowException; import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.Charsets; import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -311,7 +311,7 @@ public final class NdefRecord implements Parcelable {
if (packageName.length() == 0) throw new IllegalArgumentException("packageName is empty"); if (packageName.length() == 0) throw new IllegalArgumentException("packageName is empty");
return new NdefRecord(TNF_EXTERNAL_TYPE, RTD_ANDROID_APP, null, return new NdefRecord(TNF_EXTERNAL_TYPE, RTD_ANDROID_APP, null,
packageName.getBytes(Charsets.UTF_8)); packageName.getBytes(StandardCharsets.UTF_8));
} }
/** /**
@ -350,7 +350,7 @@ public final class NdefRecord implements Parcelable {
break; break;
} }
} }
byte[] uriBytes = uriString.getBytes(Charsets.UTF_8); byte[] uriBytes = uriString.getBytes(StandardCharsets.UTF_8);
byte[] recordBytes = new byte[uriBytes.length + 1]; byte[] recordBytes = new byte[uriBytes.length + 1];
recordBytes[0] = prefix; recordBytes[0] = prefix;
System.arraycopy(uriBytes, 0, recordBytes, 1, uriBytes.length); System.arraycopy(uriBytes, 0, recordBytes, 1, uriBytes.length);
@ -422,7 +422,7 @@ public final class NdefRecord implements Parcelable {
// missing '/' is allowed // missing '/' is allowed
// MIME RFCs suggest ASCII encoding for content-type // MIME RFCs suggest ASCII encoding for content-type
byte[] typeBytes = mimeType.getBytes(Charsets.US_ASCII); byte[] typeBytes = mimeType.getBytes(StandardCharsets.US_ASCII);
return new NdefRecord(TNF_MIME_MEDIA, typeBytes, null, mimeData); return new NdefRecord(TNF_MIME_MEDIA, typeBytes, null, mimeData);
} }
@ -462,8 +462,8 @@ public final class NdefRecord implements Parcelable {
if (domain.length() == 0) throw new IllegalArgumentException("domain is empty"); if (domain.length() == 0) throw new IllegalArgumentException("domain is empty");
if (type.length() == 0) throw new IllegalArgumentException("type is empty"); if (type.length() == 0) throw new IllegalArgumentException("type is empty");
byte[] byteDomain = domain.getBytes(Charsets.UTF_8); byte[] byteDomain = domain.getBytes(StandardCharsets.UTF_8);
byte[] byteType = type.getBytes(Charsets.UTF_8); byte[] byteType = type.getBytes(StandardCharsets.UTF_8);
byte[] b = new byte[byteDomain.length + 1 + byteType.length]; byte[] b = new byte[byteDomain.length + 1 + byteType.length];
System.arraycopy(byteDomain, 0, b, 0, byteDomain.length); System.arraycopy(byteDomain, 0, b, 0, byteDomain.length);
b[byteDomain.length] = ':'; b[byteDomain.length] = ':';
@ -643,7 +643,7 @@ public final class NdefRecord implements Parcelable {
} }
break; break;
case NdefRecord.TNF_MIME_MEDIA: case NdefRecord.TNF_MIME_MEDIA:
String mimeType = new String(mType, Charsets.US_ASCII); String mimeType = new String(mType, StandardCharsets.US_ASCII);
return Intent.normalizeMimeType(mimeType); return Intent.normalizeMimeType(mimeType);
} }
return null; return null;
@ -694,14 +694,14 @@ public final class NdefRecord implements Parcelable {
break; break;
case TNF_ABSOLUTE_URI: case TNF_ABSOLUTE_URI:
Uri uri = Uri.parse(new String(mType, Charsets.UTF_8)); Uri uri = Uri.parse(new String(mType, StandardCharsets.UTF_8));
return uri.normalizeScheme(); return uri.normalizeScheme();
case TNF_EXTERNAL_TYPE: case TNF_EXTERNAL_TYPE:
if (inSmartPoster) { if (inSmartPoster) {
break; break;
} }
return Uri.parse("vnd.android.nfc://ext/" + new String(mType, Charsets.US_ASCII)); return Uri.parse("vnd.android.nfc://ext/" + new String(mType, StandardCharsets.US_ASCII));
} }
return null; return null;
} }
@ -723,7 +723,7 @@ public final class NdefRecord implements Parcelable {
} }
String prefix = URI_PREFIX_MAP[prefixIndex]; String prefix = URI_PREFIX_MAP[prefixIndex];
String suffix = new String(Arrays.copyOfRange(mPayload, 1, mPayload.length), String suffix = new String(Arrays.copyOfRange(mPayload, 1, mPayload.length),
Charsets.UTF_8); StandardCharsets.UTF_8);
return Uri.parse(prefix + suffix); return Uri.parse(prefix + suffix);
} }

View File

@ -22,7 +22,7 @@ import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import java.net.InetAddress; import java.net.InetAddress;
import java.nio.charset.Charsets; import java.nio.charset.StandardCharsets;
/** /**
* Parcel-like entity class for VPN profiles. To keep things simple, all * Parcel-like entity class for VPN profiles. To keep things simple, all
@ -117,7 +117,7 @@ public class VpnProfile implements Cloneable, Parcelable {
return null; return null;
} }
String[] values = new String(value, Charsets.UTF_8).split("\0", -1); String[] values = new String(value, StandardCharsets.UTF_8).split("\0", -1);
// There can be 14 or 15 values in ICS MR1. // There can be 14 or 15 values in ICS MR1.
if (values.length < 14 || values.length > 15) { if (values.length < 14 || values.length > 15) {
return null; return null;
@ -167,7 +167,7 @@ public class VpnProfile implements Cloneable, Parcelable {
builder.append('\0').append(ipsecUserCert); builder.append('\0').append(ipsecUserCert);
builder.append('\0').append(ipsecCaCert); builder.append('\0').append(ipsecCaCert);
builder.append('\0').append(ipsecServerCert); builder.append('\0').append(ipsecServerCert);
return builder.toString().getBytes(Charsets.UTF_8); return builder.toString().getBytes(StandardCharsets.UTF_8);
} }
/** /**

View File

@ -19,13 +19,13 @@ package com.android.internal.util;
import java.io.Closeable; import java.io.Closeable;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.charset.Charsets; import java.nio.charset.StandardCharsets;
/** /**
* Reader that specializes in parsing {@code /proc/} files quickly. Walks * Reader that specializes in parsing {@code /proc/} files quickly. Walks
* through the stream using a single space {@code ' '} as token separator, and * through the stream using a single space {@code ' '} as token separator, and
* requires each line boundary to be explicitly acknowledged using * requires each line boundary to be explicitly acknowledged using
* {@link #finishLine()}. Assumes {@link Charsets#US_ASCII} encoding. * {@link #finishLine()}. Assumes {@link StandardCharsets#US_ASCII} encoding.
* <p> * <p>
* Currently doesn't support formats based on {@code \0}, tabs, or repeated * Currently doesn't support formats based on {@code \0}, tabs, or repeated
* delimiters. * delimiters.
@ -144,7 +144,7 @@ public class ProcFileReader implements Closeable {
*/ */
public String nextString() throws IOException { public String nextString() throws IOException {
final int tokenIndex = nextTokenIndex(); final int tokenIndex = nextTokenIndex();
final String s = new String(mBuffer, 0, tokenIndex, Charsets.US_ASCII); final String s = new String(mBuffer, 0, tokenIndex, StandardCharsets.US_ASCII);
consumeBuf(tokenIndex + 1); consumeBuf(tokenIndex + 1);
return s; return s;
} }
@ -179,7 +179,7 @@ public class ProcFileReader implements Closeable {
private NumberFormatException invalidLong(int tokenIndex) { private NumberFormatException invalidLong(int tokenIndex) {
return new NumberFormatException( return new NumberFormatException(
"invalid long: " + new String(mBuffer, 0, tokenIndex, Charsets.US_ASCII)); "invalid long: " + new String(mBuffer, 0, tokenIndex, StandardCharsets.US_ASCII));
} }
/** /**

View File

@ -20,7 +20,7 @@ import android.test.AndroidTestCase;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.Charsets; import java.nio.charset.StandardCharsets;
/** /**
* Tests for {@link ProcFileReader}. * Tests for {@link ProcFileReader}.
@ -158,6 +158,6 @@ public class ProcFileReaderTest extends AndroidTestCase {
private static ProcFileReader buildReader(String string, int bufferSize) throws IOException { private static ProcFileReader buildReader(String string, int bufferSize) throws IOException {
return new ProcFileReader( return new ProcFileReader(
new ByteArrayInputStream(string.getBytes(Charsets.US_ASCII)), bufferSize); new ByteArrayInputStream(string.getBytes(StandardCharsets.US_ASCII)), bufferSize);
} }
} }

View File

@ -31,7 +31,7 @@ import java.io.ObjectOutputStream;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.io.Reader; import java.io.Reader;
import java.io.Writer; import java.io.Writer;
import java.nio.charset.Charsets; import java.nio.charset.StandardCharsets;
import java.security.KeyPair; import java.security.KeyPair;
import java.security.cert.Certificate; import java.security.cert.Certificate;
import java.security.cert.CertificateEncodingException; import java.security.cert.CertificateEncodingException;
@ -127,7 +127,7 @@ public class Credentials {
public static byte[] convertToPem(Certificate... objects) public static byte[] convertToPem(Certificate... objects)
throws IOException, CertificateEncodingException { throws IOException, CertificateEncodingException {
ByteArrayOutputStream bao = new ByteArrayOutputStream(); ByteArrayOutputStream bao = new ByteArrayOutputStream();
Writer writer = new OutputStreamWriter(bao, Charsets.US_ASCII); Writer writer = new OutputStreamWriter(bao, StandardCharsets.US_ASCII);
PemWriter pw = new PemWriter(writer); PemWriter pw = new PemWriter(writer);
for (Certificate o : objects) { for (Certificate o : objects) {
pw.writeObject(new PemObject("CERTIFICATE", o.getEncoded())); pw.writeObject(new PemObject("CERTIFICATE", o.getEncoded()));
@ -142,7 +142,7 @@ public class Credentials {
public static List<X509Certificate> convertFromPem(byte[] bytes) public static List<X509Certificate> convertFromPem(byte[] bytes)
throws IOException, CertificateException { throws IOException, CertificateException {
ByteArrayInputStream bai = new ByteArrayInputStream(bytes); ByteArrayInputStream bai = new ByteArrayInputStream(bytes);
Reader reader = new InputStreamReader(bai, Charsets.US_ASCII); Reader reader = new InputStreamReader(bai, StandardCharsets.US_ASCII);
PemReader pr = new PemReader(reader); PemReader pr = new PemReader(reader);
CertificateFactory cf = CertificateFactory.getInstance("X509"); CertificateFactory cf = CertificateFactory.getInstance("X509");

View File

@ -22,7 +22,7 @@ import android.security.KeyStore;
import android.test.ActivityUnitTestCase; import android.test.ActivityUnitTestCase;
import android.test.AssertionFailedError; import android.test.AssertionFailedError;
import android.test.suitebuilder.annotation.MediumTest; import android.test.suitebuilder.annotation.MediumTest;
import java.nio.charset.Charsets; import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
@ -45,11 +45,11 @@ public class KeyStoreTest extends ActivityUnitTestCase<Activity> {
private static final String TEST_KEYNAME = "test-key"; private static final String TEST_KEYNAME = "test-key";
private static final String TEST_KEYNAME1 = "test-key.1"; private static final String TEST_KEYNAME1 = "test-key.1";
private static final String TEST_KEYNAME2 = "test-key\02"; private static final String TEST_KEYNAME2 = "test-key\02";
private static final byte[] TEST_KEYVALUE = "test value".getBytes(Charsets.UTF_8); private static final byte[] TEST_KEYVALUE = "test value".getBytes(StandardCharsets.UTF_8);
// "Hello, World" in Chinese // "Hello, World" in Chinese
private static final String TEST_I18N_KEY = "\u4F60\u597D, \u4E16\u754C"; private static final String TEST_I18N_KEY = "\u4F60\u597D, \u4E16\u754C";
private static final byte[] TEST_I18N_VALUE = TEST_I18N_KEY.getBytes(Charsets.UTF_8); private static final byte[] TEST_I18N_VALUE = TEST_I18N_KEY.getBytes(StandardCharsets.UTF_8);
// Test vector data for signatures // Test vector data for signatures
private static final byte[] TEST_DATA = new byte[256]; private static final byte[] TEST_DATA = new byte[256];

View File

@ -28,12 +28,12 @@ import android.util.Slog;
import com.android.internal.annotations.VisibleForTesting; import com.android.internal.annotations.VisibleForTesting;
import com.google.android.collect.Lists; import com.google.android.collect.Lists;
import java.nio.charset.Charsets;
import java.io.FileDescriptor; import java.io.FileDescriptor;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.ArrayBlockingQueue;
@ -142,7 +142,7 @@ final class NativeDaemonConnector implements Runnable, Handler.Callback, Watchdo
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
if (buffer[i] == 0) { if (buffer[i] == 0) {
final String rawEvent = new String( final String rawEvent = new String(
buffer, start, i - start, Charsets.UTF_8); buffer, start, i - start, StandardCharsets.UTF_8);
log("RCV <- {" + rawEvent + "}"); log("RCV <- {" + rawEvent + "}");
try { try {
@ -163,7 +163,7 @@ final class NativeDaemonConnector implements Runnable, Handler.Callback, Watchdo
} }
} }
if (start == 0) { if (start == 0) {
final String rawEvent = new String(buffer, start, count, Charsets.UTF_8); final String rawEvent = new String(buffer, start, count, StandardCharsets.UTF_8);
log("RCV incomplete <- {" + rawEvent + "}"); log("RCV incomplete <- {" + rawEvent + "}");
} }
@ -319,7 +319,7 @@ final class NativeDaemonConnector implements Runnable, Handler.Callback, Watchdo
throw new NativeDaemonConnectorException("missing output stream"); throw new NativeDaemonConnectorException("missing output stream");
} else { } else {
try { try {
mOutputStream.write(sentCmd.getBytes(Charsets.UTF_8)); mOutputStream.write(sentCmd.getBytes(StandardCharsets.UTF_8));
} catch (IOException e) { } catch (IOException e) {
throw new NativeDaemonConnectorException("problem sending command", e); throw new NativeDaemonConnectorException("problem sending command", e);
} }

View File

@ -69,7 +69,7 @@ import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.Inet4Address; import java.net.Inet4Address;
import java.net.InetAddress; import java.net.InetAddress;
import java.nio.charset.Charsets; import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
import libcore.io.IoUtils; import libcore.io.IoUtils;
@ -477,15 +477,15 @@ public class Vpn extends BaseNetworkStateTracker {
if (!profile.ipsecUserCert.isEmpty()) { if (!profile.ipsecUserCert.isEmpty()) {
privateKey = Credentials.USER_PRIVATE_KEY + profile.ipsecUserCert; privateKey = Credentials.USER_PRIVATE_KEY + profile.ipsecUserCert;
byte[] value = keyStore.get(Credentials.USER_CERTIFICATE + profile.ipsecUserCert); byte[] value = keyStore.get(Credentials.USER_CERTIFICATE + profile.ipsecUserCert);
userCert = (value == null) ? null : new String(value, Charsets.UTF_8); userCert = (value == null) ? null : new String(value, StandardCharsets.UTF_8);
} }
if (!profile.ipsecCaCert.isEmpty()) { if (!profile.ipsecCaCert.isEmpty()) {
byte[] value = keyStore.get(Credentials.CA_CERTIFICATE + profile.ipsecCaCert); byte[] value = keyStore.get(Credentials.CA_CERTIFICATE + profile.ipsecCaCert);
caCert = (value == null) ? null : new String(value, Charsets.UTF_8); caCert = (value == null) ? null : new String(value, StandardCharsets.UTF_8);
} }
if (!profile.ipsecServerCert.isEmpty()) { if (!profile.ipsecServerCert.isEmpty()) {
byte[] value = keyStore.get(Credentials.USER_CERTIFICATE + profile.ipsecServerCert); byte[] value = keyStore.get(Credentials.USER_CERTIFICATE + profile.ipsecServerCert);
serverCert = (value == null) ? null : new String(value, Charsets.UTF_8); serverCert = (value == null) ? null : new String(value, StandardCharsets.UTF_8);
} }
if (privateKey == null || userCert == null || caCert == null || serverCert == null) { if (privateKey == null || userCert == null || caCert == null || serverCert == null) {
throw new IllegalStateException("Cannot load credentials"); throw new IllegalStateException("Cannot load credentials");
@ -756,7 +756,7 @@ public class Vpn extends BaseNetworkStateTracker {
// Send over the arguments. // Send over the arguments.
OutputStream out = mSockets[i].getOutputStream(); OutputStream out = mSockets[i].getOutputStream();
for (String argument : arguments) { for (String argument : arguments) {
byte[] bytes = argument.getBytes(Charsets.UTF_8); byte[] bytes = argument.getBytes(StandardCharsets.UTF_8);
if (bytes.length >= 0xFFFF) { if (bytes.length >= 0xFFFF) {
throw new IllegalArgumentException("Argument is too large"); throw new IllegalArgumentException("Argument is too large");
} }