Make DataSourceException use PlaybackException error codes.
- Use `PlaybackException.ErrorCode` IntDef for `DataSourceException` error code - Deprecate `DataSourceException.POSITION_OUT_OF_RANGE` - All other changes are related to replacing the deprecated constant and constructor PiperOrigin-RevId: 382683522
This commit is contained in:
parent
ee0d905eed
commit
747b0f057b
@ -24,6 +24,7 @@ import android.text.TextUtils;
|
|||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
import com.google.android.exoplayer2.ExoPlayerLibraryInfo;
|
import com.google.android.exoplayer2.ExoPlayerLibraryInfo;
|
||||||
|
import com.google.android.exoplayer2.PlaybackException;
|
||||||
import com.google.android.exoplayer2.upstream.BaseDataSource;
|
import com.google.android.exoplayer2.upstream.BaseDataSource;
|
||||||
import com.google.android.exoplayer2.upstream.DataSource;
|
import com.google.android.exoplayer2.upstream.DataSource;
|
||||||
import com.google.android.exoplayer2.upstream.DataSourceException;
|
import com.google.android.exoplayer2.upstream.DataSourceException;
|
||||||
@ -675,7 +676,10 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource {
|
|||||||
dataSpec,
|
dataSpec,
|
||||||
responseBody);
|
responseBody);
|
||||||
if (responseCode == 416) {
|
if (responseCode == 416) {
|
||||||
exception.initCause(new DataSourceException(DataSourceException.POSITION_OUT_OF_RANGE));
|
exception.initCause(
|
||||||
|
new DataSourceException(
|
||||||
|
PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE,
|
||||||
|
DataSourceException.TYPE_READ));
|
||||||
}
|
}
|
||||||
throw exception;
|
throw exception;
|
||||||
}
|
}
|
||||||
@ -717,7 +721,9 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (!skipFully(bytesToSkip)) {
|
if (!skipFully(bytesToSkip)) {
|
||||||
throw new DataSourceException(DataSourceException.POSITION_OUT_OF_RANGE);
|
throw new DataSourceException(
|
||||||
|
PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE,
|
||||||
|
DataSourceException.TYPE_READ);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new OpenException(e, dataSpec, Status.READING_RESPONSE);
|
throw new OpenException(e, dataSpec, Status.READING_RESPONSE);
|
||||||
|
@ -23,6 +23,7 @@ import android.net.Uri;
|
|||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
import com.google.android.exoplayer2.ExoPlayerLibraryInfo;
|
import com.google.android.exoplayer2.ExoPlayerLibraryInfo;
|
||||||
|
import com.google.android.exoplayer2.PlaybackException;
|
||||||
import com.google.android.exoplayer2.upstream.BaseDataSource;
|
import com.google.android.exoplayer2.upstream.BaseDataSource;
|
||||||
import com.google.android.exoplayer2.upstream.DataSource;
|
import com.google.android.exoplayer2.upstream.DataSource;
|
||||||
import com.google.android.exoplayer2.upstream.DataSourceException;
|
import com.google.android.exoplayer2.upstream.DataSourceException;
|
||||||
@ -323,7 +324,10 @@ public class OkHttpDataSource extends BaseDataSource implements HttpDataSource {
|
|||||||
new InvalidResponseCodeException(
|
new InvalidResponseCodeException(
|
||||||
responseCode, response.message(), headers, dataSpec, errorResponseBody);
|
responseCode, response.message(), headers, dataSpec, errorResponseBody);
|
||||||
if (responseCode == 416) {
|
if (responseCode == 416) {
|
||||||
exception.initCause(new DataSourceException(DataSourceException.POSITION_OUT_OF_RANGE));
|
exception.initCause(
|
||||||
|
new DataSourceException(
|
||||||
|
PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE,
|
||||||
|
DataSourceException.TYPE_READ));
|
||||||
}
|
}
|
||||||
throw exception;
|
throw exception;
|
||||||
}
|
}
|
||||||
@ -354,7 +358,9 @@ public class OkHttpDataSource extends BaseDataSource implements HttpDataSource {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (!skipFully(bytesToSkip)) {
|
if (!skipFully(bytesToSkip)) {
|
||||||
throw new DataSourceException(DataSourceException.POSITION_OUT_OF_RANGE);
|
throw new DataSourceException(
|
||||||
|
PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE,
|
||||||
|
DataSourceException.TYPE_READ);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
closeConnectionQuietly();
|
closeConnectionQuietly();
|
||||||
|
@ -57,6 +57,7 @@ public class PlaybackException extends Exception implements Bundleable {
|
|||||||
ERROR_CODE_IO_FILE_NOT_FOUND,
|
ERROR_CODE_IO_FILE_NOT_FOUND,
|
||||||
ERROR_CODE_IO_NO_PERMISSION,
|
ERROR_CODE_IO_NO_PERMISSION,
|
||||||
ERROR_CODE_IO_CLEARTEXT_NOT_PERMITTED,
|
ERROR_CODE_IO_CLEARTEXT_NOT_PERMITTED,
|
||||||
|
ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE,
|
||||||
ERROR_CODE_PARSING_CONTAINER_MALFORMED,
|
ERROR_CODE_PARSING_CONTAINER_MALFORMED,
|
||||||
ERROR_CODE_PARSING_MANIFEST_MALFORMED,
|
ERROR_CODE_PARSING_MANIFEST_MALFORMED,
|
||||||
ERROR_CODE_PARSING_CONTAINER_UNSUPPORTED,
|
ERROR_CODE_PARSING_CONTAINER_UNSUPPORTED,
|
||||||
@ -124,6 +125,8 @@ public class PlaybackException extends Exception implements Bundleable {
|
|||||||
* troubleshooting topic</a>.
|
* troubleshooting topic</a>.
|
||||||
*/
|
*/
|
||||||
public static final int ERROR_CODE_IO_CLEARTEXT_NOT_PERMITTED = 2009;
|
public static final int ERROR_CODE_IO_CLEARTEXT_NOT_PERMITTED = 2009;
|
||||||
|
/** Caused by reading data out of the data bound. */
|
||||||
|
public static final int ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE = 2010;
|
||||||
|
|
||||||
// Content parsing errors (3xxx).
|
// Content parsing errors (3xxx).
|
||||||
|
|
||||||
@ -224,6 +227,8 @@ public class PlaybackException extends Exception implements Bundleable {
|
|||||||
return "ERROR_CODE_IO_NO_PERMISSION";
|
return "ERROR_CODE_IO_NO_PERMISSION";
|
||||||
case ERROR_CODE_IO_CLEARTEXT_NOT_PERMITTED:
|
case ERROR_CODE_IO_CLEARTEXT_NOT_PERMITTED:
|
||||||
return "ERROR_CODE_IO_CLEARTEXT_NOT_PERMITTED";
|
return "ERROR_CODE_IO_CLEARTEXT_NOT_PERMITTED";
|
||||||
|
case ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE:
|
||||||
|
return "ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE";
|
||||||
case ERROR_CODE_PARSING_CONTAINER_MALFORMED:
|
case ERROR_CODE_PARSING_CONTAINER_MALFORMED:
|
||||||
return "ERROR_CODE_PARSING_CONTAINER_MALFORMED";
|
return "ERROR_CODE_PARSING_CONTAINER_MALFORMED";
|
||||||
case ERROR_CODE_PARSING_MANIFEST_MALFORMED:
|
case ERROR_CODE_PARSING_MANIFEST_MALFORMED:
|
||||||
|
@ -17,6 +17,7 @@ package com.google.android.exoplayer2.upstream;
|
|||||||
|
|
||||||
import androidx.annotation.IntDef;
|
import androidx.annotation.IntDef;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
import com.google.android.exoplayer2.PlaybackException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.annotation.Documented;
|
import java.lang.annotation.Documented;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
@ -43,14 +44,15 @@ public class DataSourceException extends IOException {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the given {@link IOException} was caused by a {@link DataSourceException} whose
|
* Returns whether the given {@link IOException} was caused by a {@link DataSourceException} whose
|
||||||
* {@link #reason} is {@link #POSITION_OUT_OF_RANGE} in its cause stack.
|
* {@link #reason} is {@link PlaybackException#ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE} in its
|
||||||
|
* cause stack.
|
||||||
*/
|
*/
|
||||||
public static boolean isCausedByPositionOutOfRange(IOException e) {
|
public static boolean isCausedByPositionOutOfRange(IOException e) {
|
||||||
@Nullable Throwable cause = e;
|
@Nullable Throwable cause = e;
|
||||||
while (cause != null) {
|
while (cause != null) {
|
||||||
if (cause instanceof DataSourceException) {
|
if (cause instanceof DataSourceException) {
|
||||||
int reason = ((DataSourceException) cause).reason;
|
int reason = ((DataSourceException) cause).reason;
|
||||||
if (reason == DataSourceException.POSITION_OUT_OF_RANGE) {
|
if (reason == PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -62,17 +64,18 @@ public class DataSourceException extends IOException {
|
|||||||
/**
|
/**
|
||||||
* Indicates that the {@link DataSpec#position starting position} of the request was outside the
|
* Indicates that the {@link DataSpec#position starting position} of the request was outside the
|
||||||
* bounds of the data.
|
* bounds of the data.
|
||||||
|
*
|
||||||
|
* @deprecated Use {@link PlaybackException#ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE}.
|
||||||
*/
|
*/
|
||||||
public static final int POSITION_OUT_OF_RANGE = 0;
|
@Deprecated
|
||||||
|
public static final int POSITION_OUT_OF_RANGE =
|
||||||
/** Indicates that the error reason is unknown. */
|
PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE;
|
||||||
public static final int REASON_UNKNOWN = 1;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The reason of this {@link DataSourceException}. It can only be {@link #POSITION_OUT_OF_RANGE},
|
* The reason of this {@link DataSourceException}, should be one of the {@code ERROR_CODE_IO_*} in
|
||||||
* or {@link #REASON_UNKNOWN}.
|
* {@link PlaybackException.ErrorCode}.
|
||||||
*/
|
*/
|
||||||
public final int reason;
|
@PlaybackException.ErrorCode public final int reason;
|
||||||
|
|
||||||
/** The {@link Type} of the operation that caused the playback failure. */
|
/** The {@link Type} of the operation that caused the playback failure. */
|
||||||
@Type public final int type;
|
@Type public final int type;
|
||||||
@ -81,8 +84,7 @@ public class DataSourceException extends IOException {
|
|||||||
* Constructs a DataSourceException with type {@link #TYPE_READ}.
|
* Constructs a DataSourceException with type {@link #TYPE_READ}.
|
||||||
*
|
*
|
||||||
* @deprecated Use the constructor {@link #DataSourceException(String, Throwable, int, int)}.
|
* @deprecated Use the constructor {@link #DataSourceException(String, Throwable, int, int)}.
|
||||||
* @param reason Reason of the error. It can only be {@link #POSITION_OUT_OF_RANGE} or {@link
|
* @param reason Reason of the error. It should only be {@link #POSITION_OUT_OF_RANGE}.
|
||||||
* #REASON_UNKNOWN}.
|
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public DataSourceException(int reason) {
|
public DataSourceException(int reason) {
|
||||||
@ -95,11 +97,12 @@ public class DataSourceException extends IOException {
|
|||||||
*
|
*
|
||||||
* @param message The error message.
|
* @param message The error message.
|
||||||
* @param cause The error cause.
|
* @param cause The error cause.
|
||||||
* @param reason Reason of the error. It can only be {@link #POSITION_OUT_OF_RANGE} or {@link
|
* @param reason Reason of the error, should be one of the {@code ERROR_CODE_IO_*} in {@link
|
||||||
* #REASON_UNKNOWN}.
|
* PlaybackException.ErrorCode}.
|
||||||
* @param type See {@link Type}.
|
* @param type See {@link Type}.
|
||||||
*/
|
*/
|
||||||
public DataSourceException(String message, Throwable cause, int reason, @Type int type) {
|
public DataSourceException(
|
||||||
|
String message, Throwable cause, @PlaybackException.ErrorCode int reason, @Type int type) {
|
||||||
super(message, cause);
|
super(message, cause);
|
||||||
this.reason = reason;
|
this.reason = reason;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
@ -109,11 +112,12 @@ public class DataSourceException extends IOException {
|
|||||||
* Constructs a DataSourceException.
|
* Constructs a DataSourceException.
|
||||||
*
|
*
|
||||||
* @param cause The error cause.
|
* @param cause The error cause.
|
||||||
* @param reason Reason of the error. It can only be {@link #POSITION_OUT_OF_RANGE} or {@link
|
* @param reason Reason of the error, should be one of the {@code ERROR_CODE_IO_*} in {@link
|
||||||
* #REASON_UNKNOWN}.
|
* PlaybackException.ErrorCode}.
|
||||||
* @param type See {@link Type}.
|
* @param type See {@link Type}.
|
||||||
*/
|
*/
|
||||||
public DataSourceException(Throwable cause, int reason, @Type int type) {
|
public DataSourceException(
|
||||||
|
Throwable cause, @PlaybackException.ErrorCode int reason, @Type int type) {
|
||||||
super(cause);
|
super(cause);
|
||||||
this.reason = reason;
|
this.reason = reason;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
@ -123,11 +127,12 @@ public class DataSourceException extends IOException {
|
|||||||
* Constructs a DataSourceException.
|
* Constructs a DataSourceException.
|
||||||
*
|
*
|
||||||
* @param message The error message.
|
* @param message The error message.
|
||||||
* @param reason Reason of the error. It can only be {@link #POSITION_OUT_OF_RANGE} or {@link
|
* @param reason Reason of the error, should be one of the {@code ERROR_CODE_IO_*} in {@link
|
||||||
* #REASON_UNKNOWN}.
|
* PlaybackException.ErrorCode}.
|
||||||
* @param type See {@link Type}.
|
* @param type See {@link Type}.
|
||||||
*/
|
*/
|
||||||
public DataSourceException(String message, int reason, @Type int type) {
|
public DataSourceException(
|
||||||
|
String message, @PlaybackException.ErrorCode int reason, @Type int type) {
|
||||||
super(message);
|
super(message);
|
||||||
this.reason = reason;
|
this.reason = reason;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
@ -136,11 +141,11 @@ public class DataSourceException extends IOException {
|
|||||||
/**
|
/**
|
||||||
* Constructs a DataSourceException.
|
* Constructs a DataSourceException.
|
||||||
*
|
*
|
||||||
* @param reason Reason of the error. It can only be {@link #POSITION_OUT_OF_RANGE} or {@link
|
* @param reason Reason of the error, should be one of the {@code ERROR_CODE_IO_*} in {@link
|
||||||
* #REASON_UNKNOWN}.
|
* PlaybackException.ErrorCode}.
|
||||||
* @param type See {@link Type}.
|
* @param type See {@link Type}.
|
||||||
*/
|
*/
|
||||||
public DataSourceException(int reason, @Type int type) {
|
public DataSourceException(@PlaybackException.ErrorCode int reason, @Type int type) {
|
||||||
this.reason = reason;
|
this.reason = reason;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ import android.net.Uri;
|
|||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
|
import com.google.android.exoplayer2.PlaybackException;
|
||||||
import com.google.android.exoplayer2.upstream.DataSpec.HttpMethod;
|
import com.google.android.exoplayer2.upstream.DataSpec.HttpMethod;
|
||||||
import com.google.android.exoplayer2.util.Log;
|
import com.google.android.exoplayer2.util.Log;
|
||||||
import com.google.android.exoplayer2.util.Util;
|
import com.google.android.exoplayer2.util.Util;
|
||||||
@ -395,7 +396,10 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou
|
|||||||
new InvalidResponseCodeException(
|
new InvalidResponseCodeException(
|
||||||
responseCode, responseMessage, headers, dataSpec, errorResponseBody);
|
responseCode, responseMessage, headers, dataSpec, errorResponseBody);
|
||||||
if (responseCode == 416) {
|
if (responseCode == 416) {
|
||||||
exception.initCause(new DataSourceException(DataSourceException.POSITION_OUT_OF_RANGE));
|
exception.initCause(
|
||||||
|
new DataSourceException(
|
||||||
|
PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE,
|
||||||
|
DataSourceException.TYPE_READ));
|
||||||
}
|
}
|
||||||
throw exception;
|
throw exception;
|
||||||
}
|
}
|
||||||
@ -447,7 +451,9 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (!skipFully(bytesToSkip)) {
|
if (!skipFully(bytesToSkip)) {
|
||||||
throw new DataSourceException(DataSourceException.POSITION_OUT_OF_RANGE);
|
throw new DataSourceException(
|
||||||
|
PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE,
|
||||||
|
DataSourceException.TYPE_READ);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
closeConnectionQuietly();
|
closeConnectionQuietly();
|
||||||
|
@ -17,6 +17,7 @@ package com.google.android.exoplayer2.upstream;
|
|||||||
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
import com.google.android.exoplayer2.PlaybackException;
|
||||||
import com.google.android.exoplayer2.util.Util;
|
import com.google.android.exoplayer2.util.Util;
|
||||||
import com.google.common.base.Ascii;
|
import com.google.common.base.Ascii;
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
@ -190,23 +191,23 @@ public interface HttpDataSource extends DataSource {
|
|||||||
public final DataSpec dataSpec;
|
public final DataSpec dataSpec;
|
||||||
|
|
||||||
public HttpDataSourceException(DataSpec dataSpec, @Type int type) {
|
public HttpDataSourceException(DataSpec dataSpec, @Type int type) {
|
||||||
super(REASON_UNKNOWN, type);
|
super(PlaybackException.ERROR_CODE_IO_UNSPECIFIED, type);
|
||||||
this.dataSpec = dataSpec;
|
this.dataSpec = dataSpec;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpDataSourceException(String message, DataSpec dataSpec, @Type int type) {
|
public HttpDataSourceException(String message, DataSpec dataSpec, @Type int type) {
|
||||||
super(message, REASON_UNKNOWN, type);
|
super(message, PlaybackException.ERROR_CODE_IO_UNSPECIFIED, type);
|
||||||
this.dataSpec = dataSpec;
|
this.dataSpec = dataSpec;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpDataSourceException(IOException cause, DataSpec dataSpec, @Type int type) {
|
public HttpDataSourceException(IOException cause, DataSpec dataSpec, @Type int type) {
|
||||||
super(cause, REASON_UNKNOWN, type);
|
super(cause, PlaybackException.ERROR_CODE_IO_UNSPECIFIED, type);
|
||||||
this.dataSpec = dataSpec;
|
this.dataSpec = dataSpec;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpDataSourceException(
|
public HttpDataSourceException(
|
||||||
String message, IOException cause, DataSpec dataSpec, @Type int type) {
|
String message, IOException cause, DataSpec dataSpec, @Type int type) {
|
||||||
super(message, cause, REASON_UNKNOWN, type);
|
super(message, cause, PlaybackException.ERROR_CODE_IO_UNSPECIFIED, type);
|
||||||
this.dataSpec = dataSpec;
|
this.dataSpec = dataSpec;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ package com.google.android.exoplayer2.upstream;
|
|||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
import com.google.android.exoplayer2.PlaybackException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@ -26,30 +27,38 @@ import org.junit.runner.RunWith;
|
|||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class DataSourceExceptionTest {
|
public class DataSourceExceptionTest {
|
||||||
|
|
||||||
private static final int REASON_OTHER = DataSourceException.POSITION_OUT_OF_RANGE - 1;
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isCausedByPositionOutOfRange_reasonIsPositionOutOfRange_returnsTrue() {
|
public void isCausedByPositionOutOfRange_reasonIsPositionOutOfRange_returnsTrue() {
|
||||||
DataSourceException e = new DataSourceException(DataSourceException.POSITION_OUT_OF_RANGE);
|
DataSourceException e =
|
||||||
|
new DataSourceException(
|
||||||
|
PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE,
|
||||||
|
DataSourceException.TYPE_READ);
|
||||||
assertThat(DataSourceException.isCausedByPositionOutOfRange(e)).isTrue();
|
assertThat(DataSourceException.isCausedByPositionOutOfRange(e)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isCausedByPositionOutOfRange_reasonIsOther_returnsFalse() {
|
public void isCausedByPositionOutOfRange_reasonIsOther_returnsFalse() {
|
||||||
DataSourceException e = new DataSourceException(REASON_OTHER);
|
DataSourceException e =
|
||||||
|
new DataSourceException(
|
||||||
|
PlaybackException.ERROR_CODE_IO_UNSPECIFIED, DataSourceException.TYPE_READ);
|
||||||
assertThat(DataSourceException.isCausedByPositionOutOfRange(e)).isFalse();
|
assertThat(DataSourceException.isCausedByPositionOutOfRange(e)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isCausedByPositionOutOfRange_indirectauseReasonIsPositionOutOfRange_returnsTrue() {
|
public void isCausedByPositionOutOfRange_indirectauseReasonIsPositionOutOfRange_returnsTrue() {
|
||||||
DataSourceException cause = new DataSourceException(DataSourceException.POSITION_OUT_OF_RANGE);
|
DataSourceException cause =
|
||||||
|
new DataSourceException(
|
||||||
|
PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE,
|
||||||
|
DataSourceException.TYPE_READ);
|
||||||
IOException e = new IOException(new IOException(cause));
|
IOException e = new IOException(new IOException(cause));
|
||||||
assertThat(DataSourceException.isCausedByPositionOutOfRange(e)).isTrue();
|
assertThat(DataSourceException.isCausedByPositionOutOfRange(e)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isCausedByPositionOutOfRange_causeReasonIsOther_returnsFalse() {
|
public void isCausedByPositionOutOfRange_causeReasonIsOther_returnsFalse() {
|
||||||
DataSourceException cause = new DataSourceException(REASON_OTHER);
|
DataSourceException cause =
|
||||||
|
new DataSourceException(
|
||||||
|
PlaybackException.ERROR_CODE_IO_UNSPECIFIED, DataSourceException.TYPE_READ);
|
||||||
IOException e = new IOException(new IOException(cause));
|
IOException e = new IOException(new IOException(cause));
|
||||||
assertThat(DataSourceException.isCausedByPositionOutOfRange(e)).isFalse();
|
assertThat(DataSourceException.isCausedByPositionOutOfRange(e)).isFalse();
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ import android.content.res.AssetManager;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
|
import com.google.android.exoplayer2.PlaybackException;
|
||||||
import com.google.android.exoplayer2.util.Assertions;
|
import com.google.android.exoplayer2.util.Assertions;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@ -67,7 +68,9 @@ public final class AssetDataSource extends BaseDataSource {
|
|||||||
if (skipped < dataSpec.position) {
|
if (skipped < dataSpec.position) {
|
||||||
// assetManager.open() returns an AssetInputStream, whose skip() implementation only skips
|
// assetManager.open() returns an AssetInputStream, whose skip() implementation only skips
|
||||||
// fewer bytes than requested if the skip is beyond the end of the asset's data.
|
// fewer bytes than requested if the skip is beyond the end of the asset's data.
|
||||||
throw new DataSourceException(DataSourceException.POSITION_OUT_OF_RANGE);
|
throw new DataSourceException(
|
||||||
|
PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE,
|
||||||
|
DataSourceException.TYPE_READ);
|
||||||
}
|
}
|
||||||
if (dataSpec.length != C.LENGTH_UNSET) {
|
if (dataSpec.length != C.LENGTH_UNSET) {
|
||||||
bytesRemaining = dataSpec.length;
|
bytesRemaining = dataSpec.length;
|
||||||
|
@ -20,6 +20,7 @@ import static java.lang.Math.min;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
|
import com.google.android.exoplayer2.PlaybackException;
|
||||||
import com.google.android.exoplayer2.util.Assertions;
|
import com.google.android.exoplayer2.util.Assertions;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@ -46,7 +47,9 @@ public final class ByteArrayDataSource extends BaseDataSource {
|
|||||||
uri = dataSpec.uri;
|
uri = dataSpec.uri;
|
||||||
transferInitializing(dataSpec);
|
transferInitializing(dataSpec);
|
||||||
if (dataSpec.position > data.length) {
|
if (dataSpec.position > data.length) {
|
||||||
throw new DataSourceException(DataSourceException.POSITION_OUT_OF_RANGE);
|
throw new DataSourceException(
|
||||||
|
PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE,
|
||||||
|
DataSourceException.TYPE_READ);
|
||||||
}
|
}
|
||||||
readPosition = (int) dataSpec.position;
|
readPosition = (int) dataSpec.position;
|
||||||
bytesRemaining = data.length - (int) dataSpec.position;
|
bytesRemaining = data.length - (int) dataSpec.position;
|
||||||
|
@ -24,6 +24,7 @@ import android.content.res.AssetFileDescriptor;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
|
import com.google.android.exoplayer2.PlaybackException;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -79,7 +80,9 @@ public final class ContentDataSource extends BaseDataSource {
|
|||||||
// file.
|
// file.
|
||||||
if (assetFileDescriptorLength != AssetFileDescriptor.UNKNOWN_LENGTH
|
if (assetFileDescriptorLength != AssetFileDescriptor.UNKNOWN_LENGTH
|
||||||
&& dataSpec.position > assetFileDescriptorLength) {
|
&& dataSpec.position > assetFileDescriptorLength) {
|
||||||
throw new DataSourceException(DataSourceException.POSITION_OUT_OF_RANGE);
|
throw new DataSourceException(
|
||||||
|
PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE,
|
||||||
|
DataSourceException.TYPE_READ);
|
||||||
}
|
}
|
||||||
long assetFileDescriptorOffset = assetFileDescriptor.getStartOffset();
|
long assetFileDescriptorOffset = assetFileDescriptor.getStartOffset();
|
||||||
long skipped =
|
long skipped =
|
||||||
@ -88,7 +91,9 @@ public final class ContentDataSource extends BaseDataSource {
|
|||||||
if (skipped != dataSpec.position) {
|
if (skipped != dataSpec.position) {
|
||||||
// We expect the skip to be satisfied in full. If it isn't then we're probably trying to
|
// We expect the skip to be satisfied in full. If it isn't then we're probably trying to
|
||||||
// read beyond the end of the last resource in the file.
|
// read beyond the end of the last resource in the file.
|
||||||
throw new DataSourceException(DataSourceException.POSITION_OUT_OF_RANGE);
|
throw new DataSourceException(
|
||||||
|
PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE,
|
||||||
|
DataSourceException.TYPE_READ);
|
||||||
}
|
}
|
||||||
if (assetFileDescriptorLength == AssetFileDescriptor.UNKNOWN_LENGTH) {
|
if (assetFileDescriptorLength == AssetFileDescriptor.UNKNOWN_LENGTH) {
|
||||||
// The asset must extend to the end of the file. We can try and resolve the length with
|
// The asset must extend to the end of the file. We can try and resolve the length with
|
||||||
@ -101,13 +106,17 @@ public final class ContentDataSource extends BaseDataSource {
|
|||||||
bytesRemaining = channelSize - channel.position();
|
bytesRemaining = channelSize - channel.position();
|
||||||
if (bytesRemaining < 0) {
|
if (bytesRemaining < 0) {
|
||||||
// The skip above was satisfied in full, but skipped beyond the end of the file.
|
// The skip above was satisfied in full, but skipped beyond the end of the file.
|
||||||
throw new DataSourceException(DataSourceException.POSITION_OUT_OF_RANGE);
|
throw new DataSourceException(
|
||||||
|
PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE,
|
||||||
|
DataSourceException.TYPE_READ);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
bytesRemaining = assetFileDescriptorLength - skipped;
|
bytesRemaining = assetFileDescriptorLength - skipped;
|
||||||
if (bytesRemaining < 0) {
|
if (bytesRemaining < 0) {
|
||||||
throw new DataSourceException(DataSourceException.POSITION_OUT_OF_RANGE);
|
throw new DataSourceException(
|
||||||
|
PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE,
|
||||||
|
DataSourceException.TYPE_READ);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -23,6 +23,7 @@ import android.util.Base64;
|
|||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
import com.google.android.exoplayer2.ParserException;
|
import com.google.android.exoplayer2.ParserException;
|
||||||
|
import com.google.android.exoplayer2.PlaybackException;
|
||||||
import com.google.android.exoplayer2.util.Assertions;
|
import com.google.android.exoplayer2.util.Assertions;
|
||||||
import com.google.android.exoplayer2.util.Util;
|
import com.google.android.exoplayer2.util.Util;
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
@ -69,7 +70,9 @@ public final class DataSchemeDataSource extends BaseDataSource {
|
|||||||
}
|
}
|
||||||
if (dataSpec.position > data.length) {
|
if (dataSpec.position > data.length) {
|
||||||
data = null;
|
data = null;
|
||||||
throw new DataSourceException(DataSourceException.POSITION_OUT_OF_RANGE);
|
throw new DataSourceException(
|
||||||
|
PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE,
|
||||||
|
DataSourceException.TYPE_READ);
|
||||||
}
|
}
|
||||||
readPosition = (int) dataSpec.position;
|
readPosition = (int) dataSpec.position;
|
||||||
bytesRemaining = data.length - readPosition;
|
bytesRemaining = data.length - readPosition;
|
||||||
|
@ -22,6 +22,7 @@ import android.net.Uri;
|
|||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
|
import com.google.android.exoplayer2.PlaybackException;
|
||||||
import com.google.android.exoplayer2.util.Assertions;
|
import com.google.android.exoplayer2.util.Assertions;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -90,7 +91,9 @@ public final class FileDataSource extends BaseDataSource {
|
|||||||
bytesRemaining =
|
bytesRemaining =
|
||||||
dataSpec.length == C.LENGTH_UNSET ? file.length() - dataSpec.position : dataSpec.length;
|
dataSpec.length == C.LENGTH_UNSET ? file.length() - dataSpec.position : dataSpec.length;
|
||||||
if (bytesRemaining < 0) {
|
if (bytesRemaining < 0) {
|
||||||
throw new DataSourceException(DataSourceException.POSITION_OUT_OF_RANGE);
|
throw new DataSourceException(
|
||||||
|
PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE,
|
||||||
|
DataSourceException.TYPE_READ);
|
||||||
}
|
}
|
||||||
} catch (FileDataSourceException e) {
|
} catch (FileDataSourceException e) {
|
||||||
throw e;
|
throw e;
|
||||||
|
@ -26,6 +26,7 @@ import android.net.Uri;
|
|||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
|
import com.google.android.exoplayer2.PlaybackException;
|
||||||
import com.google.android.exoplayer2.util.Assertions;
|
import com.google.android.exoplayer2.util.Assertions;
|
||||||
import java.io.EOFException;
|
import java.io.EOFException;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
@ -156,7 +157,9 @@ public final class RawResourceDataSource extends BaseDataSource {
|
|||||||
// extends to the end of the file.
|
// extends to the end of the file.
|
||||||
if (assetFileDescriptorLength != AssetFileDescriptor.UNKNOWN_LENGTH
|
if (assetFileDescriptorLength != AssetFileDescriptor.UNKNOWN_LENGTH
|
||||||
&& dataSpec.position > assetFileDescriptorLength) {
|
&& dataSpec.position > assetFileDescriptorLength) {
|
||||||
throw new DataSourceException(DataSourceException.POSITION_OUT_OF_RANGE);
|
throw new DataSourceException(
|
||||||
|
PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE,
|
||||||
|
DataSourceException.TYPE_READ);
|
||||||
}
|
}
|
||||||
long assetFileDescriptorOffset = assetFileDescriptor.getStartOffset();
|
long assetFileDescriptorOffset = assetFileDescriptor.getStartOffset();
|
||||||
long skipped =
|
long skipped =
|
||||||
@ -165,7 +168,9 @@ public final class RawResourceDataSource extends BaseDataSource {
|
|||||||
if (skipped != dataSpec.position) {
|
if (skipped != dataSpec.position) {
|
||||||
// We expect the skip to be satisfied in full. If it isn't then we're probably trying to
|
// We expect the skip to be satisfied in full. If it isn't then we're probably trying to
|
||||||
// read beyond the end of the last resource in the file.
|
// read beyond the end of the last resource in the file.
|
||||||
throw new DataSourceException(DataSourceException.POSITION_OUT_OF_RANGE);
|
throw new DataSourceException(
|
||||||
|
PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE,
|
||||||
|
DataSourceException.TYPE_READ);
|
||||||
}
|
}
|
||||||
if (assetFileDescriptorLength == AssetFileDescriptor.UNKNOWN_LENGTH) {
|
if (assetFileDescriptorLength == AssetFileDescriptor.UNKNOWN_LENGTH) {
|
||||||
// The asset must extend to the end of the file. We can try and resolve the length with
|
// The asset must extend to the end of the file. We can try and resolve the length with
|
||||||
@ -177,13 +182,17 @@ public final class RawResourceDataSource extends BaseDataSource {
|
|||||||
bytesRemaining = channel.size() - channel.position();
|
bytesRemaining = channel.size() - channel.position();
|
||||||
if (bytesRemaining < 0) {
|
if (bytesRemaining < 0) {
|
||||||
// The skip above was satisfied in full, but skipped beyond the end of the file.
|
// The skip above was satisfied in full, but skipped beyond the end of the file.
|
||||||
throw new DataSourceException(DataSourceException.POSITION_OUT_OF_RANGE);
|
throw new DataSourceException(
|
||||||
|
PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE,
|
||||||
|
DataSourceException.TYPE_READ);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
bytesRemaining = assetFileDescriptorLength - skipped;
|
bytesRemaining = assetFileDescriptorLength - skipped;
|
||||||
if (bytesRemaining < 0) {
|
if (bytesRemaining < 0) {
|
||||||
throw new DataSourceException(DataSourceException.POSITION_OUT_OF_RANGE);
|
throw new DataSourceException(
|
||||||
|
PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE,
|
||||||
|
DataSourceException.TYPE_READ);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -23,6 +23,7 @@ import android.net.Uri;
|
|||||||
import androidx.annotation.IntDef;
|
import androidx.annotation.IntDef;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
|
import com.google.android.exoplayer2.PlaybackException;
|
||||||
import com.google.android.exoplayer2.upstream.DataSink;
|
import com.google.android.exoplayer2.upstream.DataSink;
|
||||||
import com.google.android.exoplayer2.upstream.DataSource;
|
import com.google.android.exoplayer2.upstream.DataSource;
|
||||||
import com.google.android.exoplayer2.upstream.DataSourceException;
|
import com.google.android.exoplayer2.upstream.DataSourceException;
|
||||||
@ -573,7 +574,9 @@ public final class CacheDataSource implements DataSource {
|
|||||||
if (bytesRemaining != C.LENGTH_UNSET) {
|
if (bytesRemaining != C.LENGTH_UNSET) {
|
||||||
bytesRemaining -= dataSpec.position;
|
bytesRemaining -= dataSpec.position;
|
||||||
if (bytesRemaining < 0) {
|
if (bytesRemaining < 0) {
|
||||||
throw new DataSourceException(DataSourceException.POSITION_OUT_OF_RANGE);
|
throw new DataSourceException(
|
||||||
|
PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE,
|
||||||
|
DataSourceException.TYPE_READ);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ import static org.junit.Assert.fail;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
|
import com.google.android.exoplayer2.PlaybackException;
|
||||||
import com.google.android.exoplayer2.util.Util;
|
import com.google.android.exoplayer2.util.Util;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@ -103,7 +104,7 @@ public final class DataSchemeDataSourceTest {
|
|||||||
buildDataSpec(DATA_SCHEME_URI, /* position= */ 108, /* length= */ C.LENGTH_UNSET));
|
buildDataSpec(DATA_SCHEME_URI, /* position= */ 108, /* length= */ C.LENGTH_UNSET));
|
||||||
fail();
|
fail();
|
||||||
} catch (DataSourceException e) {
|
} catch (DataSourceException e) {
|
||||||
assertThat(e.reason).isEqualTo(DataSourceException.POSITION_OUT_OF_RANGE);
|
assertThat(e.reason).isEqualTo(PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ import static java.lang.Math.min;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
|
import com.google.android.exoplayer2.PlaybackException;
|
||||||
import com.google.android.exoplayer2.testutil.FakeDataSet.FakeData;
|
import com.google.android.exoplayer2.testutil.FakeDataSet.FakeData;
|
||||||
import com.google.android.exoplayer2.testutil.FakeDataSet.FakeData.Segment;
|
import com.google.android.exoplayer2.testutil.FakeDataSet.FakeData.Segment;
|
||||||
import com.google.android.exoplayer2.upstream.BaseDataSource;
|
import com.google.android.exoplayer2.upstream.BaseDataSource;
|
||||||
@ -116,7 +117,9 @@ public class FakeDataSource extends BaseDataSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (dataSpec.position > totalLength) {
|
if (dataSpec.position > totalLength) {
|
||||||
throw new DataSourceException(DataSourceException.POSITION_OUT_OF_RANGE);
|
throw new DataSourceException(
|
||||||
|
PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE,
|
||||||
|
DataSourceException.TYPE_READ);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scan through the segments, configuring them for the current read.
|
// Scan through the segments, configuring them for the current read.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user