use of com.google.android.exoplayer2.upstream.DataSpec in project ExoPlayer by google.
the class ExtractorUtilTest method peekToLength_endReached.
@Test
public void peekToLength_endReached() throws Exception {
FakeDataSource testDataSource = new FakeDataSource();
testDataSource.getDataSet().newDefaultData().appendReadData(Arrays.copyOf(TEST_DATA, 3)).appendReadData(Arrays.copyOfRange(TEST_DATA, 3, 6)).appendReadData(Arrays.copyOfRange(TEST_DATA, 6, 9));
testDataSource.open(new DataSpec(Uri.parse(TEST_URI)));
ExtractorInput input = new DefaultExtractorInput(testDataSource, 0, C.LENGTH_UNSET);
byte[] target = new byte[TEST_DATA.length];
int offset = 0;
int length = TEST_DATA.length + 1;
int bytesPeeked = ExtractorUtil.peekToLength(input, target, offset, length);
assertThat(bytesPeeked).isEqualTo(TEST_DATA.length);
assertThat(input.getPeekPosition()).isEqualTo(TEST_DATA.length);
assertThat(target).isEqualTo(TEST_DATA);
}
use of com.google.android.exoplayer2.upstream.DataSpec in project ExoPlayer by google.
the class ExtractorUtilTest method peekToLength_endNotReached.
@Test
public void peekToLength_endNotReached() throws Exception {
FakeDataSource testDataSource = new FakeDataSource();
testDataSource.getDataSet().newDefaultData().appendReadData(Arrays.copyOf(TEST_DATA, 3)).appendReadData(Arrays.copyOfRange(TEST_DATA, 3, 6)).appendReadData(Arrays.copyOfRange(TEST_DATA, 6, 9));
testDataSource.open(new DataSpec(Uri.parse(TEST_URI)));
ExtractorInput input = new DefaultExtractorInput(testDataSource, 0, C.LENGTH_UNSET);
byte[] target = new byte[TEST_DATA.length];
int offset = 2;
int length = 4;
int bytesPeeked = ExtractorUtil.peekToLength(input, target, offset, length);
assertThat(bytesPeeked).isEqualTo(length);
assertThat(input.getPeekPosition()).isEqualTo(length);
assertThat(Arrays.copyOfRange(target, offset, offset + length)).isEqualTo(Arrays.copyOf(TEST_DATA, length));
}
use of com.google.android.exoplayer2.upstream.DataSpec in project ExoPlayer by google.
the class ExtractorUtilTest method peekFullyQuietly_endReachedWithEndOfInputAllowed_isFalse.
@Test
public void peekFullyQuietly_endReachedWithEndOfInputAllowed_isFalse() throws Exception {
FakeDataSource testDataSource = new FakeDataSource();
testDataSource.getDataSet().newDefaultData().appendReadData(Arrays.copyOf(TEST_DATA, 3));
testDataSource.open(new DataSpec(Uri.parse(TEST_URI)));
ExtractorInput input = new DefaultExtractorInput(testDataSource, 0, C.LENGTH_UNSET);
byte[] target = new byte[TEST_DATA.length];
int offset = 0;
int length = TEST_DATA.length + 1;
boolean hasRead = ExtractorUtil.peekFullyQuietly(input, target, offset, length, /* allowEndOfInput= */
true);
assertThat(hasRead).isFalse();
assertThat(input.getPeekPosition()).isEqualTo(0);
}
use of com.google.android.exoplayer2.upstream.DataSpec in project ExoPlayer by google.
the class ExtractorUtilTest method peekFullyQuietly_endReachedWithoutEndOfInputAllowed_throws.
@Test
public void peekFullyQuietly_endReachedWithoutEndOfInputAllowed_throws() throws Exception {
FakeDataSource testDataSource = new FakeDataSource();
testDataSource.getDataSet().newDefaultData().appendReadData(Arrays.copyOf(TEST_DATA, 3));
testDataSource.open(new DataSpec(Uri.parse(TEST_URI)));
ExtractorInput input = new DefaultExtractorInput(testDataSource, 0, C.LENGTH_UNSET);
byte[] target = new byte[TEST_DATA.length];
int offset = 0;
int length = TEST_DATA.length + 1;
assertThrows(EOFException.class, () -> ExtractorUtil.peekFullyQuietly(input, target, offset, length, /* allowEndOfInput= */
false));
assertThat(input.getPeekPosition()).isEqualTo(0);
}
use of com.google.android.exoplayer2.upstream.DataSpec in project ExoPlayer by google.
the class ExtractorUtilTest method skipFullyQuietly_endNotReached_isTrueAndSkipsData.
@Test
public void skipFullyQuietly_endNotReached_isTrueAndSkipsData() throws Exception {
FakeDataSource testDataSource = new FakeDataSource();
testDataSource.getDataSet().newDefaultData().appendReadData(Arrays.copyOf(TEST_DATA, 3)).appendReadData(Arrays.copyOfRange(TEST_DATA, 3, 6)).appendReadData(Arrays.copyOfRange(TEST_DATA, 6, 9));
testDataSource.open(new DataSpec(Uri.parse(TEST_URI)));
ExtractorInput input = new DefaultExtractorInput(testDataSource, 0, C.LENGTH_UNSET);
int length = 4;
boolean hasRead = ExtractorUtil.skipFullyQuietly(input, length);
assertThat(hasRead).isTrue();
assertThat(input.getPosition()).isEqualTo(length);
}
Aggregations