use of com.google.android.exoplayer2.upstream.DataSpec in project ExoPlayer by google.
the class DefaultExtractorInputTest method buildFailingDataSource.
private static FakeDataSource buildFailingDataSource() throws Exception {
FakeDataSource testDataSource = new FakeDataSource();
testDataSource.getDataSet().newDefaultData().appendReadData(Arrays.copyOfRange(TEST_DATA, 0, 6)).appendReadError(new IOException()).appendReadData(Arrays.copyOfRange(TEST_DATA, 6, 9));
testDataSource.open(new DataSpec(Uri.parse(TEST_URI)));
return testDataSource;
}
use of com.google.android.exoplayer2.upstream.DataSpec in project ExoPlayer by google.
the class ExtractorUtilTest method peekFullyQuietly_endNotReached_isTrueAndPeeksData.
@Test
public void peekFullyQuietly_endNotReached_isTrueAndPeeksData() 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;
boolean hasRead = ExtractorUtil.peekFullyQuietly(input, target, offset, length, /* allowEndOfInput= */
false);
assertThat(hasRead).isTrue();
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 readFullyQuietly_endReached_isFalse.
@Test
public void readFullyQuietly_endReached_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.readFullyQuietly(input, target, offset, length);
assertThat(hasRead).isFalse();
assertThat(input.getPosition()).isEqualTo(0);
}
use of com.google.android.exoplayer2.upstream.DataSpec in project ExoPlayer by google.
the class ExtractorUtilTest method skipFullyQuietly_endReached_isFalse.
@Test
public void skipFullyQuietly_endReached_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);
int length = TEST_DATA.length + 1;
boolean hasRead = ExtractorUtil.skipFullyQuietly(input, length);
assertThat(hasRead).isFalse();
assertThat(input.getPosition()).isEqualTo(0);
}
use of com.google.android.exoplayer2.upstream.DataSpec in project ExoPlayer by google.
the class ExtractorUtilTest method readFullyQuietly_endNotReached_isTrueAndReadsData.
@Test
public void readFullyQuietly_endNotReached_isTrueAndReadsData() 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;
boolean hasRead = ExtractorUtil.readFullyQuietly(input, target, offset, length);
assertThat(hasRead).isTrue();
assertThat(input.getPosition()).isEqualTo(length);
assertThat(Arrays.copyOfRange(target, offset, offset + length)).isEqualTo(Arrays.copyOf(TEST_DATA, length));
}
Aggregations