Automated Code Change

PiperOrigin-RevId: 660491742
This commit is contained in:
kak 2024-08-07 12:25:27 -07:00 committed by Copybara-Service
parent 3763e5bc1d
commit 2202397758
23 changed files with 78 additions and 72 deletions

View File

@ -27,9 +27,9 @@ import androidx.media3.common.PlaybackException;
import androidx.media3.common.util.Assertions; import androidx.media3.common.util.Assertions;
import androidx.media3.common.util.UnstableApi; import androidx.media3.common.util.UnstableApi;
import androidx.media3.common.util.Util; import androidx.media3.common.util.Util;
import com.google.common.base.Charsets;
import java.io.IOException; import java.io.IOException;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
/** A {@link DataSource} for reading data URLs, as defined by RFC 2397. */ /** A {@link DataSource} for reading data URLs, as defined by RFC 2397. */
@UnstableApi @UnstableApi
@ -68,7 +68,7 @@ public final class DataSchemeDataSource extends BaseDataSource {
} }
} else { } else {
// TODO: Add support for other charsets. // TODO: Add support for other charsets.
data = Util.getUtf8Bytes(URLDecoder.decode(dataString, Charsets.US_ASCII.name())); data = Util.getUtf8Bytes(URLDecoder.decode(dataString, StandardCharsets.US_ASCII.name()));
} }
if (dataSpec.position > data.length) { if (dataSpec.position > data.length) {
data = null; data = null;

View File

@ -17,8 +17,8 @@ package androidx.media3.datasource.cache;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.media3.common.util.UnstableApi; import androidx.media3.common.util.UnstableApi;
import com.google.common.base.Charsets;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
@ -83,7 +83,7 @@ public final class DefaultContentMetadata implements ContentMetadata {
public final String get(String key, @Nullable String defaultValue) { public final String get(String key, @Nullable String defaultValue) {
@Nullable byte[] bytes = metadata.get(key); @Nullable byte[] bytes = metadata.get(key);
if (bytes != null) { if (bytes != null) {
return new String(bytes, Charsets.UTF_8); return new String(bytes, StandardCharsets.UTF_8);
} else { } else {
return defaultValue; return defaultValue;
} }
@ -165,7 +165,7 @@ public final class DefaultContentMetadata implements ContentMetadata {
if (value instanceof Long) { if (value instanceof Long) {
return ByteBuffer.allocate(8).putLong((Long) value).array(); return ByteBuffer.allocate(8).putLong((Long) value).array();
} else if (value instanceof String) { } else if (value instanceof String) {
return ((String) value).getBytes(Charsets.UTF_8); return ((String) value).getBytes(StandardCharsets.UTF_8);
} else if (value instanceof byte[]) { } else if (value instanceof byte[]) {
return (byte[]) value; return (byte[]) value;
} else { } else {

View File

@ -23,7 +23,7 @@ import static org.junit.Assert.assertThrows;
import androidx.media3.datasource.DataSpec; import androidx.media3.datasource.DataSpec;
import androidx.media3.datasource.HttpDataSource; import androidx.media3.datasource.HttpDataSource;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.common.base.Charsets; import java.nio.charset.StandardCharsets;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import okhttp3.Headers; import okhttp3.Headers;
@ -118,7 +118,7 @@ public class OkHttpDataSourceTest {
() -> okHttpDataSource.open(dataSpec)); () -> okHttpDataSource.open(dataSpec));
assertThat(exception.responseCode).isEqualTo(404); assertThat(exception.responseCode).isEqualTo(404);
assertThat(exception.responseBody).isEqualTo("failure msg".getBytes(Charsets.UTF_8)); assertThat(exception.responseBody).isEqualTo("failure msg".getBytes(StandardCharsets.UTF_8));
} }
@Test @Test

View File

@ -42,9 +42,9 @@ import androidx.media3.common.util.UnstableApi;
import androidx.media3.common.util.Util; import androidx.media3.common.util.Util;
import androidx.media3.exoplayer.analytics.PlayerId; import androidx.media3.exoplayer.analytics.PlayerId;
import androidx.media3.extractor.mp4.PsshAtomUtil; import androidx.media3.extractor.mp4.PsshAtomUtil;
import com.google.common.base.Charsets;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.ByteOrder; import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -541,7 +541,7 @@ public final class FrameworkMediaDrm implements ExoMediaDrm {
return data; return data;
} }
int recordLength = byteArray.readLittleEndianShort(); int recordLength = byteArray.readLittleEndianShort();
String xml = byteArray.readString(recordLength, Charsets.UTF_16LE); String xml = byteArray.readString(recordLength, StandardCharsets.UTF_16LE);
if (xml.contains("<LA_URL>")) { if (xml.contains("<LA_URL>")) {
// LA_URL already present. Do nothing. // LA_URL already present. Do nothing.
return data; return data;
@ -562,7 +562,7 @@ public final class FrameworkMediaDrm implements ExoMediaDrm {
newData.putShort((short) objectRecordCount); newData.putShort((short) objectRecordCount);
newData.putShort((short) recordType); newData.putShort((short) recordType);
newData.putShort((short) (xmlWithMockLaUrl.length() * UTF_16_BYTES_PER_CHARACTER)); newData.putShort((short) (xmlWithMockLaUrl.length() * UTF_16_BYTES_PER_CHARACTER));
newData.put(xmlWithMockLaUrl.getBytes(Charsets.UTF_16LE)); newData.put(xmlWithMockLaUrl.getBytes(StandardCharsets.UTF_16LE));
return newData.array(); return newData.array();
} }

View File

@ -33,6 +33,7 @@ import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors; import com.google.common.util.concurrent.MoreExecutors;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
@ -56,7 +57,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
Format format = new Format.Builder().setSampleMimeType(mimeType).build(); Format format = new Format.Builder().setSampleMimeType(mimeType).build();
this.externalLoader = externalLoader; this.externalLoader = externalLoader;
tracks = new TrackGroupArray(new TrackGroup(format)); tracks = new TrackGroupArray(new TrackGroup(format));
sampleData = uri.toString().getBytes(Charsets.UTF_8); sampleData = uri.toString().getBytes(StandardCharsets.UTF_8);
loadingFinished = new AtomicBoolean(); loadingFinished = new AtomicBoolean();
loadingThrowable = new AtomicReference<>(); loadingThrowable = new AtomicReference<>();
} }

View File

@ -78,7 +78,6 @@ import androidx.media3.exoplayer.upstream.LoaderErrorThrower;
import androidx.media3.exoplayer.upstream.ParsingLoadable; import androidx.media3.exoplayer.upstream.ParsingLoadable;
import androidx.media3.exoplayer.util.SntpClient; import androidx.media3.exoplayer.util.SntpClient;
import androidx.media3.extractor.text.SubtitleParser; import androidx.media3.extractor.text.SubtitleParser;
import com.google.common.base.Charsets;
import com.google.common.math.LongMath; import com.google.common.math.LongMath;
import com.google.errorprone.annotations.CanIgnoreReturnValue; import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.io.BufferedReader; import java.io.BufferedReader;
@ -86,6 +85,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.nio.charset.StandardCharsets;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.List; import java.util.List;
@ -1460,7 +1460,7 @@ public final class DashMediaSource extends BaseMediaSource {
@Override @Override
public Long parse(Uri uri, InputStream inputStream) throws IOException { public Long parse(Uri uri, InputStream inputStream) throws IOException {
String firstLine = String firstLine =
new BufferedReader(new InputStreamReader(inputStream, Charsets.UTF_8)).readLine(); new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8)).readLine();
try { try {
Matcher matcher = TIMESTAMP_WITH_TIMEZONE_PATTERN.matcher(firstLine); Matcher matcher = TIMESTAMP_WITH_TIMEZONE_PATTERN.matcher(firstLine);
if (!matcher.matches()) { if (!matcher.matches()) {

View File

@ -47,12 +47,12 @@ import androidx.media3.exoplayer.upstream.ParsingLoadable;
import androidx.media3.extractor.metadata.emsg.EventMessage; import androidx.media3.extractor.metadata.emsg.EventMessage;
import androidx.media3.extractor.mp4.PsshAtomUtil; import androidx.media3.extractor.mp4.PsshAtomUtil;
import com.google.common.base.Ascii; import com.google.common.base.Ascii;
import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -1214,7 +1214,7 @@ public class DashManifestParser extends DefaultHandler
throws XmlPullParserException, IOException { throws XmlPullParserException, IOException {
scratchOutputStream.reset(); scratchOutputStream.reset();
XmlSerializer xmlSerializer = Xml.newSerializer(); XmlSerializer xmlSerializer = Xml.newSerializer();
xmlSerializer.setOutput(scratchOutputStream, Charsets.UTF_8.name()); xmlSerializer.setOutput(scratchOutputStream, StandardCharsets.UTF_8.name());
// Start reading everything between <Event> and </Event>, and serialize them into an Xml // Start reading everything between <Event> and </Event>, and serialize them into an Xml
// byte array. // byte array.
xpp.nextToken(); xpp.nextToken();

View File

@ -32,10 +32,10 @@ import androidx.media3.extractor.metadata.emsg.EventMessage;
import androidx.media3.test.utils.TestUtil; import androidx.media3.test.utils.TestUtil;
import androidx.test.core.app.ApplicationProvider; import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import java.io.IOException; import java.io.IOException;
import java.io.StringReader; import java.io.StringReader;
import java.nio.charset.StandardCharsets;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import org.junit.Test; import org.junit.Test;
@ -149,7 +149,7 @@ public class DashManifestParserTest {
assertThat(eventStream1.events.length).isEqualTo(1); assertThat(eventStream1.events.length).isEqualTo(1);
EventMessage expectedEvent1 = EventMessage expectedEvent1 =
new EventMessage( new EventMessage(
"urn:uuid:XYZY", "call", 10000, 0, "+ 1 800 10101010".getBytes(Charsets.UTF_8)); "urn:uuid:XYZY", "call", 10000, 0, "+ 1 800 10101010".getBytes(StandardCharsets.UTF_8));
assertThat(eventStream1.events[0]).isEqualTo(expectedEvent1); assertThat(eventStream1.events[0]).isEqualTo(expectedEvent1);
assertThat(eventStream1.presentationTimesUs[0]).isEqualTo(0); assertThat(eventStream1.presentationTimesUs[0]).isEqualTo(0);
@ -157,7 +157,8 @@ public class DashManifestParserTest {
EventStream eventStream2 = period.eventStreams.get(1); EventStream eventStream2 = period.eventStreams.get(1);
assertThat(eventStream2.events.length).isEqualTo(1); assertThat(eventStream2.events.length).isEqualTo(1);
EventMessage expectedEvent2 = EventMessage expectedEvent2 =
new EventMessage("urn:uuid:with-pto", "pto-4s", 10000, 0, "pt=1s".getBytes(Charsets.UTF_8)); new EventMessage(
"urn:uuid:with-pto", "pto-4s", 10000, 0, "pt=1s".getBytes(StandardCharsets.UTF_8));
assertThat(eventStream2.events[0]).isEqualTo(expectedEvent2); assertThat(eventStream2.events[0]).isEqualTo(expectedEvent2);
assertThat(eventStream2.presentationTimesUs[0]).isEqualTo(1000000); assertThat(eventStream2.presentationTimesUs[0]).isEqualTo(1000000);

View File

@ -16,7 +16,7 @@
package androidx.media3.exoplayer.dash.offline; package androidx.media3.exoplayer.dash.offline;
import android.net.Uri; import android.net.Uri;
import com.google.common.base.Charsets; import java.nio.charset.StandardCharsets;
/** Data for DASH downloading tests. */ /** Data for DASH downloading tests. */
/* package */ interface DashDownloadTestData { /* package */ interface DashDownloadTestData {
@ -86,7 +86,7 @@ import com.google.common.base.Charsets;
+ " </AdaptationSet>\n" + " </AdaptationSet>\n"
+ " </Period>\n" + " </Period>\n"
+ "</MPD>") + "</MPD>")
.getBytes(Charsets.UTF_8); .getBytes(StandardCharsets.UTF_8);
byte[] TEST_MPD_NO_INDEX = byte[] TEST_MPD_NO_INDEX =
("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
@ -99,5 +99,5 @@ import com.google.common.base.Charsets;
+ " </AdaptationSet>\n" + " </AdaptationSet>\n"
+ " </Period>\n" + " </Period>\n"
+ "</MPD>") + "</MPD>")
.getBytes(Charsets.UTF_8); .getBytes(StandardCharsets.UTF_8);
} }

View File

@ -15,7 +15,7 @@
*/ */
package androidx.media3.exoplayer.hls.offline; package androidx.media3.exoplayer.hls.offline;
import com.google.common.base.Charsets; import java.nio.charset.StandardCharsets;
/** Data for HLS downloading tests. */ /** Data for HLS downloading tests. */
/* package */ interface HlsDownloadTestData { /* package */ interface HlsDownloadTestData {
@ -48,7 +48,7 @@ import com.google.common.base.Charsets;
+ "\n" + "\n"
+ "#EXT-X-STREAM-INF:BANDWIDTH=41457,CODECS=\"mp4a.40.2\"\n" + "#EXT-X-STREAM-INF:BANDWIDTH=41457,CODECS=\"mp4a.40.2\"\n"
+ MEDIA_PLAYLIST_0_URI) + MEDIA_PLAYLIST_0_URI)
.getBytes(Charsets.UTF_8); .getBytes(StandardCharsets.UTF_8);
byte[] MEDIA_PLAYLIST_DATA = byte[] MEDIA_PLAYLIST_DATA =
("#EXTM3U\n" ("#EXTM3U\n"
@ -63,7 +63,7 @@ import com.google.common.base.Charsets;
+ "#EXTINF:9.97667,\n" + "#EXTINF:9.97667,\n"
+ "fileSequence2.ts\n" + "fileSequence2.ts\n"
+ "#EXT-X-ENDLIST") + "#EXT-X-ENDLIST")
.getBytes(Charsets.UTF_8); .getBytes(StandardCharsets.UTF_8);
String ENC_MEDIA_PLAYLIST_URI = "enc_index.m3u8"; String ENC_MEDIA_PLAYLIST_URI = "enc_index.m3u8";
@ -82,5 +82,5 @@ import com.google.common.base.Charsets;
+ "#EXTINF:9.97667,\n" + "#EXTINF:9.97667,\n"
+ "fileSequence2.ts\n" + "fileSequence2.ts\n"
+ "#EXT-X-ENDLIST") + "#EXT-X-ENDLIST")
.getBytes(Charsets.UTF_8); .getBytes(StandardCharsets.UTF_8);
} }

View File

@ -27,9 +27,9 @@ import androidx.media3.common.ParserException;
import androidx.media3.exoplayer.hls.HlsTrackMetadataEntry; import androidx.media3.exoplayer.hls.HlsTrackMetadataEntry;
import androidx.media3.exoplayer.hls.playlist.HlsMultivariantPlaylist.Variant; import androidx.media3.exoplayer.hls.playlist.HlsMultivariantPlaylist.Variant;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.common.base.Charsets;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -482,7 +482,7 @@ public class HlsMultivariantPlaylistParserTest {
String uri, String playlistString) throws IOException { String uri, String playlistString) throws IOException {
Uri playlistUri = Uri.parse(uri); Uri playlistUri = Uri.parse(uri);
ByteArrayInputStream inputStream = ByteArrayInputStream inputStream =
new ByteArrayInputStream(playlistString.getBytes(Charsets.UTF_8)); new ByteArrayInputStream(playlistString.getBytes(StandardCharsets.UTF_8));
return (HlsMultivariantPlaylist) new HlsPlaylistParser().parse(playlistUri, inputStream); return (HlsMultivariantPlaylist) new HlsPlaylistParser().parse(playlistUri, inputStream);
} }
} }

View File

@ -31,7 +31,6 @@ import androidx.media3.exoplayer.upstream.Loader;
import androidx.media3.exoplayer.upstream.Loader.LoadErrorAction; import androidx.media3.exoplayer.upstream.Loader.LoadErrorAction;
import androidx.media3.exoplayer.upstream.Loader.Loadable; import androidx.media3.exoplayer.upstream.Loader.Loadable;
import com.google.common.base.Ascii; import com.google.common.base.Ascii;
import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.primitives.Ints; import com.google.common.primitives.Ints;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
@ -46,6 +45,7 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
import java.net.Socket; import java.net.Socket;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
@ -57,7 +57,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
/* package */ final class RtspMessageChannel implements Closeable { /* package */ final class RtspMessageChannel implements Closeable {
/** RTSP uses UTF-8 (RFC2326 Section 1.1). */ /** RTSP uses UTF-8 (RFC2326 Section 1.1). */
public static final Charset CHARSET = Charsets.UTF_8; public static final Charset CHARSET = StandardCharsets.UTF_8;
private static final String TAG = "RtspMessageChannel"; private static final String TAG = "RtspMessageChannel";

View File

@ -21,8 +21,8 @@ import androidx.media3.common.util.ParsableBitArray;
import androidx.media3.common.util.UnstableApi; import androidx.media3.common.util.UnstableApi;
import androidx.media3.extractor.metadata.MetadataInputBuffer; import androidx.media3.extractor.metadata.MetadataInputBuffer;
import androidx.media3.extractor.metadata.SimpleMetadataDecoder; import androidx.media3.extractor.metadata.SimpleMetadataDecoder;
import com.google.common.base.Charsets;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
/** /**
@ -108,7 +108,7 @@ public final class AppInfoTableDecoder extends SimpleMetadataDecoder {
// See section 5.3.6.2. // See section 5.3.6.2.
while (sectionData.getBytePosition() < positionOfNextDescriptor) { while (sectionData.getBytePosition() < positionOfNextDescriptor) {
int urlBaseLength = sectionData.readBits(8); int urlBaseLength = sectionData.readBits(8);
urlBase = sectionData.readBytesAsString(urlBaseLength, Charsets.US_ASCII); urlBase = sectionData.readBytesAsString(urlBaseLength, StandardCharsets.US_ASCII);
int extensionCount = sectionData.readBits(8); int extensionCount = sectionData.readBits(8);
for (int urlExtensionIndex = 0; for (int urlExtensionIndex = 0;
@ -121,7 +121,7 @@ public final class AppInfoTableDecoder extends SimpleMetadataDecoder {
} }
} else if (descriptorTag == DESCRIPTOR_SIMPLE_APPLICATION_LOCATION) { } else if (descriptorTag == DESCRIPTOR_SIMPLE_APPLICATION_LOCATION) {
// See section 5.3.7. // See section 5.3.7.
urlExtension = sectionData.readBytesAsString(descriptorLength, Charsets.US_ASCII); urlExtension = sectionData.readBytesAsString(descriptorLength, StandardCharsets.US_ASCII);
} }
sectionData.setPosition(positionOfNextDescriptor * 8); sectionData.setPosition(positionOfNextDescriptor * 8);

View File

@ -25,7 +25,7 @@ import androidx.media3.common.Metadata;
import androidx.media3.common.MimeTypes; import androidx.media3.common.MimeTypes;
import androidx.media3.common.util.ParsableByteArray; import androidx.media3.common.util.ParsableByteArray;
import androidx.media3.common.util.UnstableApi; import androidx.media3.common.util.UnstableApi;
import com.google.common.base.Charsets; import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
/** A picture parsed from a Vorbis Comment or a FLAC picture block. */ /** A picture parsed from a Vorbis Comment or a FLAC picture block. */
@ -161,7 +161,8 @@ public final class PictureFrame implements Metadata.Entry {
int pictureType = pictureBlock.readInt(); int pictureType = pictureBlock.readInt();
int mimeTypeLength = pictureBlock.readInt(); int mimeTypeLength = pictureBlock.readInt();
String mimeType = String mimeType =
MimeTypes.normalizeMimeType(pictureBlock.readString(mimeTypeLength, Charsets.US_ASCII)); MimeTypes.normalizeMimeType(
pictureBlock.readString(mimeTypeLength, StandardCharsets.US_ASCII));
int descriptionLength = pictureBlock.readInt(); int descriptionLength = pictureBlock.readInt();
String description = pictureBlock.readString(descriptionLength); String description = pictureBlock.readString(descriptionLength);
int width = pictureBlock.readInt(); int width = pictureBlock.readInt();

View File

@ -21,10 +21,10 @@ import androidx.media3.common.util.UnstableApi;
import androidx.media3.extractor.metadata.MetadataInputBuffer; import androidx.media3.extractor.metadata.MetadataInputBuffer;
import androidx.media3.extractor.metadata.SimpleMetadataDecoder; import androidx.media3.extractor.metadata.SimpleMetadataDecoder;
import com.google.common.base.Ascii; import com.google.common.base.Ascii;
import com.google.common.base.Charsets;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.CharacterCodingException; import java.nio.charset.CharacterCodingException;
import java.nio.charset.CharsetDecoder; import java.nio.charset.CharsetDecoder;
import java.nio.charset.StandardCharsets;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -40,8 +40,8 @@ public final class IcyDecoder extends SimpleMetadataDecoder {
private final CharsetDecoder iso88591Decoder; private final CharsetDecoder iso88591Decoder;
public IcyDecoder() { public IcyDecoder() {
utf8Decoder = Charsets.UTF_8.newDecoder(); utf8Decoder = StandardCharsets.UTF_8.newDecoder();
iso88591Decoder = Charsets.ISO_8859_1.newDecoder(); iso88591Decoder = StandardCharsets.ISO_8859_1.newDecoder();
} }
@Override @Override

View File

@ -27,10 +27,10 @@ import androidx.media3.common.util.Util;
import androidx.media3.extractor.metadata.MetadataInputBuffer; import androidx.media3.extractor.metadata.MetadataInputBuffer;
import androidx.media3.extractor.metadata.SimpleMetadataDecoder; import androidx.media3.extractor.metadata.SimpleMetadataDecoder;
import com.google.common.base.Ascii; import com.google.common.base.Ascii;
import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.Charset; import java.nio.charset.Charset;
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;
@ -525,7 +525,7 @@ public final class Id3Decoder extends SimpleMetadataDecoder {
int urlStartIndex = descriptionEndIndex + delimiterLength(encoding); int urlStartIndex = descriptionEndIndex + delimiterLength(encoding);
int urlEndIndex = indexOfZeroByte(data, urlStartIndex); int urlEndIndex = indexOfZeroByte(data, urlStartIndex);
String url = decodeStringIfValid(data, urlStartIndex, urlEndIndex, Charsets.ISO_8859_1); String url = decodeStringIfValid(data, urlStartIndex, urlEndIndex, StandardCharsets.ISO_8859_1);
return new UrlLinkFrame("WXXX", description, url); return new UrlLinkFrame("WXXX", description, url);
} }
@ -536,7 +536,7 @@ public final class Id3Decoder extends SimpleMetadataDecoder {
id3Data.readBytes(data, 0, frameSize); id3Data.readBytes(data, 0, frameSize);
int urlEndIndex = indexOfZeroByte(data, 0); int urlEndIndex = indexOfZeroByte(data, 0);
String url = new String(data, 0, urlEndIndex, Charsets.ISO_8859_1); String url = new String(data, 0, urlEndIndex, StandardCharsets.ISO_8859_1);
return new UrlLinkFrame(id, null, url); return new UrlLinkFrame(id, null, url);
} }
@ -546,7 +546,7 @@ public final class Id3Decoder extends SimpleMetadataDecoder {
id3Data.readBytes(data, 0, frameSize); id3Data.readBytes(data, 0, frameSize);
int ownerEndIndex = indexOfZeroByte(data, 0); int ownerEndIndex = indexOfZeroByte(data, 0);
String owner = new String(data, 0, ownerEndIndex, Charsets.ISO_8859_1); String owner = new String(data, 0, ownerEndIndex, StandardCharsets.ISO_8859_1);
int privateDataStartIndex = ownerEndIndex + 1; int privateDataStartIndex = ownerEndIndex + 1;
byte[] privateData = copyOfRangeIfValid(data, privateDataStartIndex, data.length); byte[] privateData = copyOfRangeIfValid(data, privateDataStartIndex, data.length);
@ -563,7 +563,8 @@ public final class Id3Decoder extends SimpleMetadataDecoder {
int mimeTypeEndIndex = indexOfZeroByte(data, 0); int mimeTypeEndIndex = indexOfZeroByte(data, 0);
String mimeType = String mimeType =
MimeTypes.normalizeMimeType(new String(data, 0, mimeTypeEndIndex, Charsets.ISO_8859_1)); MimeTypes.normalizeMimeType(
new String(data, 0, mimeTypeEndIndex, StandardCharsets.ISO_8859_1));
int filenameStartIndex = mimeTypeEndIndex + 1; int filenameStartIndex = mimeTypeEndIndex + 1;
int filenameEndIndex = indexOfTerminator(data, filenameStartIndex, encoding); int filenameEndIndex = indexOfTerminator(data, filenameStartIndex, encoding);
@ -592,13 +593,14 @@ public final class Id3Decoder extends SimpleMetadataDecoder {
int mimeTypeEndIndex; int mimeTypeEndIndex;
if (majorVersion == 2) { if (majorVersion == 2) {
mimeTypeEndIndex = 2; mimeTypeEndIndex = 2;
mimeType = "image/" + Ascii.toLowerCase(new String(data, 0, 3, Charsets.ISO_8859_1)); mimeType = "image/" + Ascii.toLowerCase(new String(data, 0, 3, StandardCharsets.ISO_8859_1));
if ("image/jpg".equals(mimeType)) { if ("image/jpg".equals(mimeType)) {
mimeType = "image/jpeg"; mimeType = "image/jpeg";
} }
} else { } else {
mimeTypeEndIndex = indexOfZeroByte(data, 0); mimeTypeEndIndex = indexOfZeroByte(data, 0);
mimeType = Ascii.toLowerCase(new String(data, 0, mimeTypeEndIndex, Charsets.ISO_8859_1)); mimeType =
Ascii.toLowerCase(new String(data, 0, mimeTypeEndIndex, StandardCharsets.ISO_8859_1));
if (mimeType.indexOf('/') == -1) { if (mimeType.indexOf('/') == -1) {
mimeType = "image/" + mimeType; mimeType = "image/" + mimeType;
} }
@ -659,7 +661,7 @@ public final class Id3Decoder extends SimpleMetadataDecoder {
id3Data.getData(), id3Data.getData(),
framePosition, framePosition,
chapterIdEndIndex - framePosition, chapterIdEndIndex - framePosition,
Charsets.ISO_8859_1); StandardCharsets.ISO_8859_1);
id3Data.setPosition(chapterIdEndIndex + 1); id3Data.setPosition(chapterIdEndIndex + 1);
int startTime = id3Data.readInt(); int startTime = id3Data.readInt();
@ -702,7 +704,7 @@ public final class Id3Decoder extends SimpleMetadataDecoder {
id3Data.getData(), id3Data.getData(),
framePosition, framePosition,
elementIdEndIndex - framePosition, elementIdEndIndex - framePosition,
Charsets.ISO_8859_1); StandardCharsets.ISO_8859_1);
id3Data.setPosition(elementIdEndIndex + 1); id3Data.setPosition(elementIdEndIndex + 1);
int ctocFlags = id3Data.readUnsignedByte(); int ctocFlags = id3Data.readUnsignedByte();
@ -715,7 +717,8 @@ public final class Id3Decoder extends SimpleMetadataDecoder {
int startIndex = id3Data.getPosition(); int startIndex = id3Data.getPosition();
int endIndex = indexOfZeroByte(id3Data.getData(), startIndex); int endIndex = indexOfZeroByte(id3Data.getData(), startIndex);
children[i] = children[i] =
new String(id3Data.getData(), startIndex, endIndex - startIndex, Charsets.ISO_8859_1); new String(
id3Data.getData(), startIndex, endIndex - startIndex, StandardCharsets.ISO_8859_1);
id3Data.setPosition(endIndex + 1); id3Data.setPosition(endIndex + 1);
} }
@ -798,14 +801,14 @@ public final class Id3Decoder extends SimpleMetadataDecoder {
private static Charset getCharset(int encodingByte) { private static Charset getCharset(int encodingByte) {
switch (encodingByte) { switch (encodingByte) {
case ID3_TEXT_ENCODING_UTF_16: case ID3_TEXT_ENCODING_UTF_16:
return Charsets.UTF_16; return StandardCharsets.UTF_16;
case ID3_TEXT_ENCODING_UTF_16BE: case ID3_TEXT_ENCODING_UTF_16BE:
return Charsets.UTF_16BE; return StandardCharsets.UTF_16BE;
case ID3_TEXT_ENCODING_UTF_8: case ID3_TEXT_ENCODING_UTF_8:
return Charsets.UTF_8; return StandardCharsets.UTF_8;
case ID3_TEXT_ENCODING_ISO_8859_1: case ID3_TEXT_ENCODING_ISO_8859_1:
default: default:
return Charsets.ISO_8859_1; return StandardCharsets.ISO_8859_1;
} }
} }

View File

@ -40,8 +40,8 @@ import androidx.media3.common.util.Util;
import androidx.media3.extractor.text.CuesWithTiming; import androidx.media3.extractor.text.CuesWithTiming;
import androidx.media3.extractor.text.SubtitleParser; import androidx.media3.extractor.text.SubtitleParser;
import com.google.common.base.Ascii; import com.google.common.base.Ascii;
import com.google.common.base.Charsets;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
@ -119,7 +119,7 @@ public final class SsaParser implements SubtitleParser {
Assertions.checkArgument(formatLine.startsWith(FORMAT_LINE_PREFIX)); Assertions.checkArgument(formatLine.startsWith(FORMAT_LINE_PREFIX));
dialogueFormatFromInitializationData = dialogueFormatFromInitializationData =
Assertions.checkNotNull(SsaDialogueFormat.fromFormatLine(formatLine)); Assertions.checkNotNull(SsaDialogueFormat.fromFormatLine(formatLine));
parseHeader(new ParsableByteArray(initializationData.get(1)), Charsets.UTF_8); parseHeader(new ParsableByteArray(initializationData.get(1)), StandardCharsets.UTF_8);
} else { } else {
haveInitializationData = false; haveInitializationData = false;
dialogueFormatFromInitializationData = null; dialogueFormatFromInitializationData = null;
@ -189,7 +189,7 @@ public final class SsaParser implements SubtitleParser {
*/ */
private Charset detectUtfCharset(ParsableByteArray data) { private Charset detectUtfCharset(ParsableByteArray data) {
@Nullable Charset charset = data.readUtfCharsetFromBom(); @Nullable Charset charset = data.readUtfCharsetFromBom();
return charset != null ? charset : Charsets.UTF_8; return charset != null ? charset : StandardCharsets.UTF_8;
} }
/** /**

View File

@ -33,9 +33,9 @@ import androidx.media3.common.util.ParsableByteArray;
import androidx.media3.common.util.UnstableApi; import androidx.media3.common.util.UnstableApi;
import androidx.media3.extractor.text.CuesWithTiming; import androidx.media3.extractor.text.CuesWithTiming;
import androidx.media3.extractor.text.SubtitleParser; import androidx.media3.extractor.text.SubtitleParser;
import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@ -193,7 +193,7 @@ public final class SubripParser implements SubtitleParser {
*/ */
private Charset detectUtfCharset(ParsableByteArray data) { private Charset detectUtfCharset(ParsableByteArray data) {
@Nullable Charset charset = data.readUtfCharsetFromBom(); @Nullable Charset charset = data.readUtfCharsetFromBom();
return charset != null ? charset : Charsets.UTF_8; return charset != null ? charset : StandardCharsets.UTF_8;
} }
/** /**

View File

@ -39,9 +39,9 @@ import androidx.media3.common.util.UnstableApi;
import androidx.media3.common.util.Util; import androidx.media3.common.util.Util;
import androidx.media3.extractor.text.CuesWithTiming; import androidx.media3.extractor.text.CuesWithTiming;
import androidx.media3.extractor.text.SubtitleParser; import androidx.media3.extractor.text.SubtitleParser;
import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.List; import java.util.List;
/** /**
@ -204,7 +204,7 @@ public final class Tx3gParser implements SubtitleParser {
@Nullable Charset charset = parsableByteArray.readUtfCharsetFromBom(); @Nullable Charset charset = parsableByteArray.readUtfCharsetFromBom();
int bomSize = parsableByteArray.getPosition() - textStartPosition; int bomSize = parsableByteArray.getPosition() - textStartPosition;
return parsableByteArray.readString( return parsableByteArray.readString(
textLength - bomSize, charset != null ? charset : Charsets.UTF_8); textLength - bomSize, charset != null ? charset : StandardCharsets.UTF_8);
} }
private void applyStyleRecord( private void applyStyleRecord(

View File

@ -25,7 +25,7 @@ import androidx.media3.common.util.Assertions;
import androidx.media3.common.util.Util; import androidx.media3.common.util.Util;
import androidx.media3.extractor.metadata.MetadataInputBuffer; import androidx.media3.extractor.metadata.MetadataInputBuffer;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.common.base.Charsets; import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -513,7 +513,7 @@ public final class Id3DecoderTest {
for (FrameSpec frame : frames) { for (FrameSpec frame : frames) {
byte[] frameData = frame.frameData; byte[] frameData = frame.frameData;
String frameId = frame.frameId; String frameId = frame.frameId;
byte[] frameIdBytes = frameId.getBytes(Charsets.UTF_8); byte[] frameIdBytes = frameId.getBytes(StandardCharsets.UTF_8);
Assertions.checkState(frameIdBytes.length == 4); Assertions.checkState(frameIdBytes.length == 4);
// Fill in the frame header. // Fill in the frame header.

View File

@ -32,12 +32,12 @@ import androidx.media3.extractor.text.SubtitleInputBuffer;
import androidx.media3.extractor.text.SubtitleOutputBuffer; import androidx.media3.extractor.text.SubtitleOutputBuffer;
import androidx.media3.test.utils.TestUtil; import androidx.media3.test.utils.TestUtil;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.primitives.Bytes; import com.google.common.primitives.Bytes;
import com.google.common.primitives.UnsignedBytes; import com.google.common.primitives.UnsignedBytes;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -72,7 +72,7 @@ public class Cea708DecoderTest {
Bytes.concat( Bytes.concat(
windowDefinition, windowDefinition,
setCurrentWindow, setCurrentWindow,
"test subtitle".getBytes(Charsets.UTF_8))))); "test subtitle".getBytes(StandardCharsets.UTF_8)))));
Subtitle firstSubtitle = decodeSampleAndCopyResult(cea708Decoder, subtitleData); Subtitle firstSubtitle = decodeSampleAndCopyResult(cea708Decoder, subtitleData);
@ -102,7 +102,7 @@ public class Cea708DecoderTest {
Bytes.concat( Bytes.concat(
windowDefinition, windowDefinition,
setCurrentWindow, setCurrentWindow,
"row1\r\nrow2\r\nrow3\r\nrow4".getBytes(Charsets.UTF_8))))); "row1\r\nrow2\r\nrow3\r\nrow4".getBytes(StandardCharsets.UTF_8)))));
Subtitle result = decodeSampleAndCopyResult(cea708Decoder, subtitleData); Subtitle result = decodeSampleAndCopyResult(cea708Decoder, subtitleData);
@ -143,9 +143,9 @@ public class Cea708DecoderTest {
Bytes.concat( Bytes.concat(
windowDefinition, windowDefinition,
setCurrentWindow, setCurrentWindow,
"line1".getBytes(Charsets.UTF_8), "line1".getBytes(StandardCharsets.UTF_8),
setPenLocation, setPenLocation,
"line2".getBytes(Charsets.UTF_8))))); "line2".getBytes(StandardCharsets.UTF_8)))));
Subtitle firstSubtitle = decodeSampleAndCopyResult(cea708Decoder, subtitleData); Subtitle firstSubtitle = decodeSampleAndCopyResult(cea708Decoder, subtitleData);
@ -186,10 +186,10 @@ public class Cea708DecoderTest {
Bytes.concat( Bytes.concat(
windowDefinition, windowDefinition,
setCurrentWindow, setCurrentWindow,
"line1".getBytes(Charsets.UTF_8), "line1".getBytes(StandardCharsets.UTF_8),
newLine, newLine,
setPenLocation, setPenLocation,
"line2".getBytes(Charsets.UTF_8))))); "line2".getBytes(StandardCharsets.UTF_8)))));
Subtitle firstSubtitle = decodeSampleAndCopyResult(cea708Decoder, subtitleData); Subtitle firstSubtitle = decodeSampleAndCopyResult(cea708Decoder, subtitleData);

View File

@ -15,8 +15,8 @@
*/ */
package androidx.media3.muxer; package androidx.media3.muxer;
import com.google.common.base.Charsets;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.List; import java.util.List;
/** Utilities for dealing with MP4 boxes. */ /** Utilities for dealing with MP4 boxes. */
@ -28,7 +28,7 @@ import java.util.List;
/** Wraps content into a box, prefixing it with a length and a box type. */ /** Wraps content into a box, prefixing it with a length and a box type. */
public static ByteBuffer wrapIntoBox(String boxType, ByteBuffer contents) { public static ByteBuffer wrapIntoBox(String boxType, ByteBuffer contents) {
byte[] typeByteArray = boxType.getBytes(Charsets.UTF_8); byte[] typeByteArray = boxType.getBytes(StandardCharsets.UTF_8);
return wrapIntoBox(typeByteArray, contents); return wrapIntoBox(typeByteArray, contents);
} }
@ -56,7 +56,7 @@ import java.util.List;
ByteBuffer result = ByteBuffer.allocate(totalSize); ByteBuffer result = ByteBuffer.allocate(totalSize);
result.putInt(totalSize); result.putInt(totalSize);
result.put(boxType.getBytes(Charsets.UTF_8), 0, BOX_TYPE_BYTES); result.put(boxType.getBytes(StandardCharsets.UTF_8), 0, BOX_TYPE_BYTES);
for (int i = 0; i < boxes.size(); i++) { for (int i = 0; i < boxes.size(); i++) {
result.put(boxes.get(i)); result.put(boxes.get(i));

View File

@ -32,7 +32,7 @@ import androidx.annotation.Nullable;
import androidx.media3.common.text.Cue; import androidx.media3.common.text.Cue;
import androidx.media3.common.util.Assertions; import androidx.media3.common.util.Assertions;
import androidx.media3.common.util.Util; import androidx.media3.common.util.Util;
import com.google.common.base.Charsets; import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
@ -329,7 +329,7 @@ import java.util.Map;
html.insert(0, htmlHead.toString()); html.insert(0, htmlHead.toString());
webView.loadData( webView.loadData(
Base64.encodeToString(html.toString().getBytes(Charsets.UTF_8), Base64.NO_PADDING), Base64.encodeToString(html.toString().getBytes(StandardCharsets.UTF_8), Base64.NO_PADDING),
"text/html", "text/html",
"base64"); "base64");
} }