@SuppressWarnings("NonAtomicVolatileUpdate") @Override public void load() throws IOException, InterruptedException { DataSpec loadDataSpec = Util.getRemainderDataSpec(dataSpec, bytesLoaded); try { // Create and open the input. ExtractorInput input = new DefaultExtractorInput(dataSource, loadDataSpec.absoluteStreamPosition, dataSource.open(loadDataSpec)); if (bytesLoaded == 0) { // Set the target to ourselves. extractorWrapper.init(this); } // Load and parse the initialization data. try { int result = Extractor.RESULT_CONTINUE; while (result == Extractor.RESULT_CONTINUE && !loadCanceled) { result = extractorWrapper.read(input); } } finally { bytesLoaded = (int) (input.getPosition() - dataSpec.absoluteStreamPosition); } } finally { dataSource.close(); } }
@SuppressWarnings("NonAtomicVolatileUpdate") @Override public final void load() throws IOException, InterruptedException { DataSpec loadDataSpec = Util.getRemainderDataSpec(dataSpec, bytesLoaded); try { // Create and open the input. ExtractorInput input = new DefaultExtractorInput(dataSource, loadDataSpec.absoluteStreamPosition, dataSource.open(loadDataSpec)); if (bytesLoaded == 0) { // Set the target to ourselves. extractorWrapper.init(this); } // Load and parse the initialization data. try { int result = Extractor.RESULT_CONTINUE; while (result == Extractor.RESULT_CONTINUE && !loadCanceled) { result = extractorWrapper.read(input); } } finally { bytesLoaded = (int) (input.getPosition() - dataSpec.absoluteStreamPosition); } } finally { dataSource.close(); } }
@SuppressWarnings("NonAtomicVolatileUpdate") @Override public final void load() throws IOException, InterruptedException { DataSpec loadDataSpec = Util.getRemainderDataSpec(dataSpec, bytesLoaded); try { // Create and open the input. ExtractorInput input = new DefaultExtractorInput(dataSource, loadDataSpec.absoluteStreamPosition, dataSource.open(loadDataSpec)); if (bytesLoaded == 0) { // Set the target to ourselves. extractorWrapper.init(this); } // Load and parse the sample data. try { int result = Extractor.RESULT_CONTINUE; while (result == Extractor.RESULT_CONTINUE && !loadCanceled) { result = extractorWrapper.read(input); } } finally { bytesLoaded = (int) (input.getPosition() - dataSpec.absoluteStreamPosition); } } finally { dataSource.close(); } }
public void testReadVarintEndOfInputAtStart() throws IOException, InterruptedException { VarintReader reader = new VarintReader(); // Build an input, and read to the end. DataSource dataSource = buildDataSource(new byte[1]); dataSource.open(new DataSpec(Uri.parse(TEST_URI))); ExtractorInput input = new DefaultExtractorInput(dataSource, 0, C.LENGTH_UNBOUNDED); int bytesRead = input.read(new byte[1], 0, 1); assertEquals(1, bytesRead); // End of input allowed. long result = reader.readUnsignedVarint(input, true, false); assertEquals(-1, result); // End of input not allowed. try { reader.readUnsignedVarint(input, false, false); fail(); } catch (EOFException e) { // Expected. } }
@Override public void load() throws IOException, InterruptedException { // If we previously fed part of this chunk to the extractor, we need to skip it this time. For // encrypted content we need to skip the data by reading it through the source, so as to ensure // correct decryption of the remainder of the chunk. For clear content, we can request the // remainder of the chunk directly. DataSpec loadDataSpec; boolean skipLoadedBytes; if (isEncrypted) { loadDataSpec = dataSpec; skipLoadedBytes = bytesLoaded != 0; } else { loadDataSpec = Util.getRemainderDataSpec(dataSpec, bytesLoaded); skipLoadedBytes = false; } try { ExtractorInput input = new DefaultExtractorInput(dataSource, loadDataSpec.absoluteStreamPosition, dataSource.open(loadDataSpec)); if (skipLoadedBytes) { input.skipFully(bytesLoaded); } try { int result = Extractor.RESULT_CONTINUE; while (result == Extractor.RESULT_CONTINUE && !loadCanceled) { result = extractorWrapper.read(input); } } finally { bytesLoaded = (int) (input.getPosition() - dataSpec.absoluteStreamPosition); } } finally { dataSource.close(); } }
@Override public void setUp() throws Exception { TestUtil.setUpMockito(this); FakeDataSource.Builder builder = new FakeDataSource.Builder(); builder.appendReadData(STREAM_DATA); FakeDataSource fakeDataSource = builder.build(); fakeDataSource.open(new DataSpec(Uri.parse(TEST_URI))); fakeExtractorInput = new DefaultExtractorInput(fakeDataSource, 0, STREAM_DATA.length); }
private static void testReadVarint(VarintReader reader, boolean removeMask, byte[] data, int expectedLength, long expectedValue) throws IOException, InterruptedException { DataSource dataSource = buildDataSource(data); dataSource.open(new DataSpec(Uri.parse(TEST_URI))); ExtractorInput input = new DefaultExtractorInput(dataSource, 0, C.LENGTH_UNBOUNDED); long result = reader.readUnsignedVarint(input, false, removeMask); assertEquals(expectedLength, input.getPosition()); assertEquals(expectedValue, result); }
/** * Helper to build an {@link ExtractorInput} from byte data. * <p> * Each argument must be able to cast to a byte value. * * @param data Zero or more integers with values between {@code 0x00} and {@code 0xFF}. * @return An {@link ExtractorInput} from which the data can be read. * @throws IOException If an error occurs creating the input. */ private static ExtractorInput createTestInput(int... data) throws IOException { byte[] bytes = new byte[data.length]; for (int i = 0; i < data.length; i++) { bytes[i] = (byte) data[i]; } DataSource dataSource = new FakeDataSource.Builder().appendReadData(bytes).build(); dataSource.open(new DataSpec(Uri.parse("http://www.google.com"))); ExtractorInput input = new DefaultExtractorInput(dataSource, 0, C.LENGTH_UNBOUNDED); return input; }
public static ExtractorInput createTestExtractorInput(byte[] data, int offset) throws IOException { if (offset != 0) { data = Arrays.copyOfRange(data, offset, data.length); } FakeDataSource dataSource = new FakeDataSource.Builder().appendReadData(data).build(); dataSource.open(new DataSpec(Uri.parse("http://www.google.com"))); ExtractorInput input = new DefaultExtractorInput(dataSource, offset, C.LENGTH_UNBOUNDED); return input; }