@Override public void advancePeekPosition(int length) throws IOException, InterruptedException { ensureSpaceForPeek(length); int peekBytes = Math.min(peekBufferLength - peekBufferPosition, length); int fillBytes = length - peekBytes; int remaining = fillBytes; int writePosition = peekBufferLength; while (remaining > 0) { if (Thread.interrupted()) { throw new InterruptedException(); } int bytesRead = dataSource.read(peekBuffer, writePosition, remaining); if (bytesRead == C.RESULT_END_OF_INPUT) { throw new EOFException(); } remaining -= bytesRead; writePosition += bytesRead; } peekBufferPosition += length; peekBufferLength += fillBytes; }
@Override public void readFully(byte[] target, int offset, int length) throws IOException, InterruptedException { readFully(target, offset, length, false); }
@Override public void skipFully(int length) throws IOException, InterruptedException { int peekBytes = Math.min(peekBufferLength, length); int remaining = length - peekBytes; while (remaining > 0) { if (Thread.interrupted()) { throw new InterruptedException(); } int bytesRead = dataSource.read(SCRATCH_SPACE, 0, Math.min(SCRATCH_SPACE.length, remaining)); if (bytesRead == C.RESULT_END_OF_INPUT) { throw new EOFException(); } remaining -= bytesRead; } updatePeekBuffer(peekBytes); position += length; }
@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(); } }
ExtractorInput input = new DefaultExtractorInput(dataSource, loadDataSpec.absoluteStreamPosition, dataSource.open(loadDataSpec)); if (skipLoadedBytes) {
@Override public int read(byte[] target, int offset, int length) throws IOException, InterruptedException { if (Thread.interrupted()) { throw new InterruptedException(); } int peekBytes = Math.min(peekBufferLength, length); System.arraycopy(peekBuffer, 0, target, offset, peekBytes); offset += peekBytes; length -= peekBytes; int bytesRead = length != 0 ? dataSource.read(target, offset, length) : 0; if (bytesRead == C.RESULT_END_OF_INPUT) { return C.RESULT_END_OF_INPUT; } updatePeekBuffer(peekBytes); bytesRead += peekBytes; position += bytesRead; return bytesRead; }
@Override public void peekFully(byte[] target, int offset, int length) throws IOException, InterruptedException { ensureSpaceForPeek(length); int peekBytes = Math.min(peekBufferLength - peekBufferPosition, length); System.arraycopy(peekBuffer, peekBufferPosition, target, offset, peekBytes); offset += peekBytes; int fillBytes = length - peekBytes; int remaining = fillBytes; int writePosition = peekBufferLength; while (remaining > 0) { if (Thread.interrupted()) { throw new InterruptedException(); } int bytesRead = dataSource.read(peekBuffer, writePosition, remaining); if (bytesRead == C.RESULT_END_OF_INPUT) { throw new EOFException(); } System.arraycopy(peekBuffer, writePosition, target, offset, bytesRead); remaining -= bytesRead; writePosition += bytesRead; offset += bytesRead; } peekBufferPosition += length; peekBufferLength += fillBytes; }
length += position; input = new DefaultExtractorInput(dataSource, position, length); Extractor extractor = extractorHolder.selectExtractor(input); if (pendingExtractorSeek) {
@Override public boolean readFully(byte[] target, int offset, int length, boolean allowEndOfInput) throws IOException, InterruptedException { int peekBytes = Math.min(peekBufferLength, length); System.arraycopy(peekBuffer, 0, target, offset, peekBytes); offset += peekBytes; int remaining = length - peekBytes; while (remaining > 0) { if (Thread.interrupted()) { throw new InterruptedException(); } int bytesRead = dataSource.read(target, offset, remaining); if (bytesRead == C.RESULT_END_OF_INPUT) { if (allowEndOfInput && remaining == length) { return false; } throw new EOFException(); } offset += bytesRead; remaining -= bytesRead; } updatePeekBuffer(peekBytes); position += length; return true; }