Replace TestUtil.joinByteArrays() with Guava's Bytes.concat()
PiperOrigin-RevId: 312481058
This commit is contained in:
parent
9035f1d701
commit
2397e7f67a
@ -17,13 +17,13 @@ package com.google.android.exoplayer2.metadata.emsg;
|
||||
|
||||
import static com.google.android.exoplayer2.testutil.TestUtil.createByteArray;
|
||||
import static com.google.android.exoplayer2.testutil.TestUtil.createMetadataInputBuffer;
|
||||
import static com.google.android.exoplayer2.testutil.TestUtil.joinByteArrays;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import com.google.android.exoplayer2.metadata.Metadata;
|
||||
import com.google.android.exoplayer2.metadata.MetadataInputBuffer;
|
||||
import com.google.common.primitives.Bytes;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@ -34,7 +34,7 @@ public final class EventMessageDecoderTest {
|
||||
@Test
|
||||
public void decodeEventMessage() {
|
||||
byte[] rawEmsgBody =
|
||||
joinByteArrays(
|
||||
Bytes.concat(
|
||||
createByteArray(117, 114, 110, 58, 116, 101, 115, 116, 0), // scheme_id_uri = "urn:test"
|
||||
createByteArray(49, 50, 51, 0), // value = "123"
|
||||
createByteArray(0, 0, 11, 184), // event_duration_ms = 3000
|
||||
|
@ -17,12 +17,12 @@ package com.google.android.exoplayer2.metadata.emsg;
|
||||
|
||||
import static com.google.android.exoplayer2.testutil.TestUtil.createByteArray;
|
||||
import static com.google.android.exoplayer2.testutil.TestUtil.createMetadataInputBuffer;
|
||||
import static com.google.android.exoplayer2.testutil.TestUtil.joinByteArrays;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import com.google.android.exoplayer2.metadata.Metadata;
|
||||
import com.google.android.exoplayer2.metadata.MetadataInputBuffer;
|
||||
import com.google.common.primitives.Bytes;
|
||||
import java.io.IOException;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@ -35,7 +35,7 @@ public final class EventMessageEncoderTest {
|
||||
new EventMessage("urn:test", "123", 3000, 1000403, new byte[] {0, 1, 2, 3, 4});
|
||||
|
||||
private static final byte[] ENCODED_MESSAGE =
|
||||
joinByteArrays(
|
||||
Bytes.concat(
|
||||
createByteArray(117, 114, 110, 58, 116, 101, 115, 116, 0), // scheme_id_uri = "urn:test"
|
||||
createByteArray(49, 50, 51, 0), // value = "123"
|
||||
createByteArray(0, 0, 11, 184), // event_duration_ms = 3000
|
||||
@ -64,7 +64,7 @@ public final class EventMessageEncoderTest {
|
||||
EventMessage eventMessage1 =
|
||||
new EventMessage("urn:test", "123", 3000, 1000402, new byte[] {4, 3, 2, 1, 0});
|
||||
byte[] expectedEmsgBody1 =
|
||||
joinByteArrays(
|
||||
Bytes.concat(
|
||||
createByteArray(117, 114, 110, 58, 116, 101, 115, 116, 0), // scheme_id_uri = "urn:test"
|
||||
createByteArray(49, 50, 51, 0), // value = "123"
|
||||
createByteArray(0, 0, 11, 184), // event_duration_ms = 3000
|
||||
|
@ -23,6 +23,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
|
||||
import com.google.android.exoplayer2.testutil.TestUtil;
|
||||
import com.google.common.primitives.Bytes;
|
||||
import java.nio.ByteBuffer;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@ -153,7 +154,7 @@ public final class BatchBufferTest {
|
||||
batchBuffer.commitNextAccessUnit();
|
||||
batchBuffer.flip();
|
||||
|
||||
byte[] expected = TestUtil.joinByteArrays(TEST_ACCESS_UNIT, TEST_ACCESS_UNIT);
|
||||
byte[] expected = Bytes.concat(TEST_ACCESS_UNIT, TEST_ACCESS_UNIT);
|
||||
assertThat(batchBuffer.data).isEqualTo(ByteBuffer.wrap(expected));
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,7 @@ import com.google.android.exoplayer2.testutil.FakeSampleStream.FakeSampleStreamI
|
||||
import com.google.android.exoplayer2.testutil.TestUtil;
|
||||
import com.google.android.exoplayer2.util.Assertions;
|
||||
import com.google.android.exoplayer2.util.MimeTypes;
|
||||
import com.google.common.primitives.Bytes;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@ -43,7 +44,7 @@ import org.junit.runner.RunWith;
|
||||
public class MetadataRendererTest {
|
||||
|
||||
private static final byte[] SCTE35_TIME_SIGNAL_BYTES =
|
||||
TestUtil.joinByteArrays(
|
||||
Bytes.concat(
|
||||
TestUtil.createByteArray(
|
||||
0, // table_id.
|
||||
0x80, // section_syntax_indicator, private_indicator, reserved, section_length(4).
|
||||
@ -170,7 +171,7 @@ public class MetadataRendererTest {
|
||||
*/
|
||||
private static byte[] encodeTxxxId3Frame(String description, String value) {
|
||||
byte[] id3FrameData =
|
||||
TestUtil.joinByteArrays(
|
||||
Bytes.concat(
|
||||
"TXXX".getBytes(ISO_8859_1), // ID for a 'user defined text information frame'
|
||||
TestUtil.createByteArray(0, 0, 0, 0), // Frame size (set later)
|
||||
TestUtil.createByteArray(0, 0), // Frame flags
|
||||
@ -186,7 +187,7 @@ public class MetadataRendererTest {
|
||||
id3FrameData[frameSizeIndex] = (byte) frameSize;
|
||||
|
||||
byte[] id3Bytes =
|
||||
TestUtil.joinByteArrays(
|
||||
Bytes.concat(
|
||||
"ID3".getBytes(ISO_8859_1), // identifier
|
||||
TestUtil.createByteArray(0x04, 0x00), // version
|
||||
TestUtil.createByteArray(0), // Tag flags
|
||||
|
@ -26,7 +26,7 @@ import static org.junit.Assert.assertThrows;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import com.google.android.exoplayer2.metadata.Metadata;
|
||||
import com.google.android.exoplayer2.metadata.MetadataInputBuffer;
|
||||
import com.google.android.exoplayer2.testutil.TestUtil;
|
||||
import com.google.common.primitives.Bytes;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@ -54,7 +54,7 @@ public final class IcyDecoderTest {
|
||||
public void decode_respectsLimit() {
|
||||
byte[] icyTitle = "StreamTitle='test title';".getBytes(UTF_8);
|
||||
byte[] icyUrl = "StreamURL='test_url';".getBytes(UTF_8);
|
||||
byte[] paddedRawBytes = TestUtil.joinByteArrays(icyTitle, icyUrl);
|
||||
byte[] paddedRawBytes = Bytes.concat(icyTitle, icyUrl);
|
||||
MetadataInputBuffer metadataBuffer = createMetadataInputBuffer(paddedRawBytes);
|
||||
// Stop before the stream URL.
|
||||
metadataBuffer.data.limit(icyTitle.length);
|
||||
|
@ -43,6 +43,7 @@ import com.google.android.exoplayer2.upstream.DefaultAllocator;
|
||||
import com.google.android.exoplayer2.util.Assertions;
|
||||
import com.google.android.exoplayer2.util.MediaSourceEventDispatcher;
|
||||
import com.google.android.exoplayer2.util.ParsableByteArray;
|
||||
import com.google.common.primitives.Bytes;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
@ -483,7 +484,7 @@ public final class SampleQueueTest {
|
||||
byte[] sampleData = new byte[] {0, 1, 2};
|
||||
byte[] initializationVector = new byte[] {7, 6, 5, 4, 3, 2, 1, 0};
|
||||
byte[] encryptedSampleData =
|
||||
TestUtil.joinByteArrays(
|
||||
Bytes.concat(
|
||||
new byte[] {
|
||||
0x08, // subsampleEncryption = false (1 bit), ivSize = 8 (7 bits).
|
||||
},
|
||||
|
@ -41,6 +41,7 @@ android {
|
||||
dependencies {
|
||||
implementation 'androidx.annotation:annotation:' + androidxAnnotationVersion
|
||||
implementation project(modulePrefix + 'library-common')
|
||||
implementation 'com.google.guava:guava:' + guavaVersion
|
||||
compileOnly 'org.checkerframework:checker-qual:' + checkerframeworkVersion
|
||||
compileOnly 'org.checkerframework:checker-compat-qual:' + checkerframeworkVersion
|
||||
compileOnly 'org.jetbrains.kotlin:kotlin-annotations-jvm:' + kotlinAnnotationsVersion
|
||||
|
@ -26,6 +26,7 @@ import com.google.android.exoplayer2.extractor.ExtractorInput;
|
||||
import com.google.android.exoplayer2.testutil.FakeExtractorInput;
|
||||
import com.google.android.exoplayer2.testutil.TestUtil;
|
||||
import com.google.android.exoplayer2.util.ParsableByteArray;
|
||||
import com.google.common.primitives.Bytes;
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.util.Random;
|
||||
@ -125,7 +126,7 @@ public final class DefaultOggSeekerTest {
|
||||
public void skipToNextPage_success() throws Exception {
|
||||
FakeExtractorInput extractorInput =
|
||||
createInput(
|
||||
TestUtil.joinByteArrays(
|
||||
Bytes.concat(
|
||||
TestUtil.buildTestData(4000, random),
|
||||
new byte[] {'O', 'g', 'g', 'S'},
|
||||
TestUtil.buildTestData(4000, random)),
|
||||
@ -138,7 +139,7 @@ public final class DefaultOggSeekerTest {
|
||||
public void skipToNextPage_withOverlappingInput_success() throws Exception {
|
||||
FakeExtractorInput extractorInput =
|
||||
createInput(
|
||||
TestUtil.joinByteArrays(
|
||||
Bytes.concat(
|
||||
TestUtil.buildTestData(2046, random),
|
||||
new byte[] {'O', 'g', 'g', 'S'},
|
||||
TestUtil.buildTestData(4000, random)),
|
||||
@ -151,8 +152,7 @@ public final class DefaultOggSeekerTest {
|
||||
public void skipToNextPage_withInputShorterThanPeekLength_success() throws Exception {
|
||||
FakeExtractorInput extractorInput =
|
||||
createInput(
|
||||
TestUtil.joinByteArrays(new byte[] {'x', 'O', 'g', 'g', 'S'}),
|
||||
/* simulateUnknownLength= */ false);
|
||||
Bytes.concat(new byte[] {'x', 'O', 'g', 'g', 'S'}), /* simulateUnknownLength= */ false);
|
||||
skipToNextPage(extractorInput);
|
||||
assertThat(extractorInput.getPosition()).isEqualTo(1);
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ import com.google.android.exoplayer2.testutil.FakeExtractorOutput;
|
||||
import com.google.android.exoplayer2.testutil.FakeTrackOutput;
|
||||
import com.google.android.exoplayer2.testutil.TestUtil;
|
||||
import com.google.android.exoplayer2.util.ParsableByteArray;
|
||||
import com.google.common.primitives.Bytes;
|
||||
import java.util.Arrays;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@ -57,7 +58,7 @@ public class AdtsReaderTest {
|
||||
TestUtil.createByteArray(0x20, 0x00, 0x20, 0x00, 0x00, 0x80, 0x0e);
|
||||
|
||||
private static final byte[] TEST_DATA =
|
||||
TestUtil.joinByteArrays(ID3_DATA_1, ID3_DATA_2, ADTS_HEADER, ADTS_CONTENT);
|
||||
Bytes.concat(ID3_DATA_1, ID3_DATA_2, ADTS_HEADER, ADTS_CONTENT);
|
||||
|
||||
private static final long ADTS_SAMPLE_DURATION = 23219L;
|
||||
|
||||
@ -94,7 +95,7 @@ public class AdtsReaderTest {
|
||||
public void skipToNextSampleResetsState() throws Exception {
|
||||
data =
|
||||
new ParsableByteArray(
|
||||
TestUtil.joinByteArrays(
|
||||
Bytes.concat(
|
||||
ADTS_HEADER,
|
||||
ADTS_CONTENT,
|
||||
ADTS_HEADER,
|
||||
|
@ -27,6 +27,7 @@ import com.google.android.exoplayer2.util.Assertions;
|
||||
import com.google.android.exoplayer2.util.Function;
|
||||
import com.google.android.exoplayer2.util.ParsableByteArray;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
import com.google.common.primitives.Bytes;
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@ -105,7 +106,7 @@ public final class FakeTrackOutput implements TrackOutput, Dumper.Dumpable {
|
||||
throw new EOFException();
|
||||
}
|
||||
newData = Arrays.copyOf(newData, bytesAppended);
|
||||
sampleData = TestUtil.joinByteArrays(sampleData, newData);
|
||||
sampleData = Bytes.concat(sampleData, newData);
|
||||
return bytesAppended;
|
||||
}
|
||||
|
||||
@ -113,7 +114,7 @@ public final class FakeTrackOutput implements TrackOutput, Dumper.Dumpable {
|
||||
public void sampleData(ParsableByteArray data, int length, @SampleDataPart int sampleDataPart) {
|
||||
byte[] newData = new byte[length];
|
||||
data.readBytes(newData, 0, length);
|
||||
sampleData = TestUtil.joinByteArrays(sampleData, newData);
|
||||
sampleData = Bytes.concat(sampleData, newData);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -168,26 +168,6 @@ public class TestUtil {
|
||||
return byteArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Concatenates the provided byte arrays.
|
||||
*
|
||||
* @param byteArrays The byte arrays to concatenate.
|
||||
* @return The concatenated result.
|
||||
*/
|
||||
public static byte[] joinByteArrays(byte[]... byteArrays) {
|
||||
int length = 0;
|
||||
for (byte[] byteArray : byteArrays) {
|
||||
length += byteArray.length;
|
||||
}
|
||||
byte[] joined = new byte[length];
|
||||
length = 0;
|
||||
for (byte[] byteArray : byteArrays) {
|
||||
System.arraycopy(byteArray, 0, joined, length, byteArray.length);
|
||||
length += byteArray.length;
|
||||
}
|
||||
return joined;
|
||||
}
|
||||
|
||||
/** Writes one byte long dummy test data to the file and returns it. */
|
||||
public static File createTestFile(File directory, String name) throws IOException {
|
||||
return createTestFile(directory, name, /* length= */ 1);
|
||||
|
Loading…
x
Reference in New Issue
Block a user