ExtractorInput.setRetryPosition(): Called when reading fails and the required retry position is different from the last position.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=124242428
This commit is contained in:
eguven 2016-06-07 07:30:34 -07:00 committed by Oliver Woodman
parent 1a1a454d09
commit cec658d573
3 changed files with 26 additions and 0 deletions

View file

@ -17,6 +17,7 @@ package com.google.android.exoplayer.extractor;
import com.google.android.exoplayer.C;
import com.google.android.exoplayer.upstream.DataSource;
import com.google.android.exoplayer.util.Assertions;
import java.io.EOFException;
import java.io.IOException;
@ -162,6 +163,13 @@ public final class DefaultExtractorInput implements ExtractorInput {
return streamLength;
}
@Override
public <E extends Throwable> void setRetryPosition(long position, E e) throws E {
Assertions.checkArgument(position >= 0);
this.position = position;
throw e;
}
/**
* Ensures {@code peekBuffer} is large enough to store at least {@code length} bytes from the
* current peek position.

View file

@ -223,4 +223,15 @@ public interface ExtractorInput {
*/
long getLength();
/**
* Called when reading fails and the required retry position is different from the last position.
* After setting the retry position it throws the given {@link Throwable}.
*
* @param <E> Type of {@link Throwable} to be thrown.
* @param position The required retry position.
* @param e {@link Throwable} to be thrown.
* @throws E The given {@link Throwable} object.
*/
<E extends Throwable> void setRetryPosition(long position, E e) throws E;
}

View file

@ -191,6 +191,13 @@ public final class FakeExtractorInput implements ExtractorInput {
return simulateUnknownLength ? C.LENGTH_UNBOUNDED : data.length;
}
@Override
public <E extends Throwable> void setRetryPosition(long position, E e) throws E {
Assert.assertTrue(position >= 0);
readPosition = (int) position;
throw e;
}
private boolean checkXFully(boolean allowEndOfInput, int position, int length,
SparseBooleanArray failedPositions) throws IOException {
if (simulateIOErrors && !failedPositions.get(position)) {