mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Move TYPE definition out from DataSourceException.
The types (open/close/read) does not provide extra information about the thrown playback exception, and they are not utilized at higher levels. PiperOrigin-RevId: 384219870
This commit is contained in:
parent
d84e19a302
commit
ca28d6a041
@ -351,12 +351,12 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource {
|
|||||||
public final int cronetConnectionStatus;
|
public final int cronetConnectionStatus;
|
||||||
|
|
||||||
public OpenException(IOException cause, DataSpec dataSpec, int cronetConnectionStatus) {
|
public OpenException(IOException cause, DataSpec dataSpec, int cronetConnectionStatus) {
|
||||||
super(cause, dataSpec, TYPE_OPEN);
|
super(cause, dataSpec, PlaybackException.ERROR_CODE_IO_UNSPECIFIED, TYPE_OPEN);
|
||||||
this.cronetConnectionStatus = cronetConnectionStatus;
|
this.cronetConnectionStatus = cronetConnectionStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OpenException(String errorMessage, DataSpec dataSpec, int cronetConnectionStatus) {
|
public OpenException(String errorMessage, DataSpec dataSpec, int cronetConnectionStatus) {
|
||||||
super(errorMessage, dataSpec, TYPE_OPEN);
|
super(errorMessage, dataSpec, PlaybackException.ERROR_CODE_IO_UNSPECIFIED, TYPE_OPEN);
|
||||||
this.cronetConnectionStatus = cronetConnectionStatus;
|
this.cronetConnectionStatus = cronetConnectionStatus;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -677,9 +677,7 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource {
|
|||||||
responseBody);
|
responseBody);
|
||||||
if (responseCode == 416) {
|
if (responseCode == 416) {
|
||||||
exception.initCause(
|
exception.initCause(
|
||||||
new DataSourceException(
|
new DataSourceException(PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE));
|
||||||
PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE,
|
|
||||||
DataSourceException.TYPE_READ));
|
|
||||||
}
|
}
|
||||||
throw exception;
|
throw exception;
|
||||||
}
|
}
|
||||||
@ -721,9 +719,7 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (!skipFully(bytesToSkip)) {
|
if (!skipFully(bytesToSkip)) {
|
||||||
throw new DataSourceException(
|
throw new DataSourceException(PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE);
|
||||||
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);
|
||||||
@ -751,7 +747,10 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource {
|
|||||||
readInternal(readBuffer);
|
readInternal(readBuffer);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new HttpDataSourceException(
|
throw new HttpDataSourceException(
|
||||||
e, castNonNull(currentDataSpec), HttpDataSourceException.TYPE_READ);
|
e,
|
||||||
|
castNonNull(currentDataSpec),
|
||||||
|
PlaybackException.ERROR_CODE_IO_UNSPECIFIED,
|
||||||
|
HttpDataSourceException.TYPE_READ);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (finished) {
|
if (finished) {
|
||||||
@ -838,7 +837,10 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource {
|
|||||||
readInternal(buffer);
|
readInternal(buffer);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new HttpDataSourceException(
|
throw new HttpDataSourceException(
|
||||||
e, castNonNull(currentDataSpec), HttpDataSourceException.TYPE_READ);
|
e,
|
||||||
|
castNonNull(currentDataSpec),
|
||||||
|
PlaybackException.ERROR_CODE_IO_UNSPECIFIED,
|
||||||
|
HttpDataSourceException.TYPE_READ);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (finished) {
|
if (finished) {
|
||||||
|
@ -295,7 +295,11 @@ public class OkHttpDataSource extends BaseDataSource implements HttpDataSource {
|
|||||||
throw new CleartextNotPermittedException(e, dataSpec);
|
throw new CleartextNotPermittedException(e, dataSpec);
|
||||||
}
|
}
|
||||||
throw new HttpDataSourceException(
|
throw new HttpDataSourceException(
|
||||||
"Unable to connect", e, dataSpec, HttpDataSourceException.TYPE_OPEN);
|
"Unable to connect",
|
||||||
|
e,
|
||||||
|
dataSpec,
|
||||||
|
PlaybackException.ERROR_CODE_IO_NETWORK_CONNECTION_FAILED,
|
||||||
|
HttpDataSourceException.TYPE_OPEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
int responseCode = response.code();
|
int responseCode = response.code();
|
||||||
@ -325,9 +329,7 @@ public class OkHttpDataSource extends BaseDataSource implements HttpDataSource {
|
|||||||
responseCode, response.message(), headers, dataSpec, errorResponseBody);
|
responseCode, response.message(), headers, dataSpec, errorResponseBody);
|
||||||
if (responseCode == 416) {
|
if (responseCode == 416) {
|
||||||
exception.initCause(
|
exception.initCause(
|
||||||
new DataSourceException(
|
new DataSourceException(PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE));
|
||||||
PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE,
|
|
||||||
DataSourceException.TYPE_READ));
|
|
||||||
}
|
}
|
||||||
throw exception;
|
throw exception;
|
||||||
}
|
}
|
||||||
@ -358,13 +360,15 @@ public class OkHttpDataSource extends BaseDataSource implements HttpDataSource {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (!skipFully(bytesToSkip)) {
|
if (!skipFully(bytesToSkip)) {
|
||||||
throw new DataSourceException(
|
throw new DataSourceException(PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE);
|
||||||
PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE,
|
|
||||||
DataSourceException.TYPE_READ);
|
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
closeConnectionQuietly();
|
closeConnectionQuietly();
|
||||||
throw new HttpDataSourceException(e, dataSpec, HttpDataSourceException.TYPE_OPEN);
|
throw new HttpDataSourceException(
|
||||||
|
e,
|
||||||
|
dataSpec,
|
||||||
|
PlaybackException.ERROR_CODE_IO_UNSPECIFIED,
|
||||||
|
HttpDataSourceException.TYPE_OPEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
return bytesToRead;
|
return bytesToRead;
|
||||||
@ -376,12 +380,15 @@ public class OkHttpDataSource extends BaseDataSource implements HttpDataSource {
|
|||||||
return readInternal(buffer, offset, readLength);
|
return readInternal(buffer, offset, readLength);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new HttpDataSourceException(
|
throw new HttpDataSourceException(
|
||||||
e, Assertions.checkNotNull(dataSpec), HttpDataSourceException.TYPE_READ);
|
e,
|
||||||
|
Assertions.checkNotNull(dataSpec),
|
||||||
|
PlaybackException.ERROR_CODE_IO_UNSPECIFIED,
|
||||||
|
HttpDataSourceException.TYPE_READ);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws HttpDataSourceException {
|
public void close() {
|
||||||
if (opened) {
|
if (opened) {
|
||||||
opened = false;
|
opened = false;
|
||||||
transferEnded();
|
transferEnded();
|
||||||
@ -397,7 +404,10 @@ public class OkHttpDataSource extends BaseDataSource implements HttpDataSource {
|
|||||||
@Nullable HttpUrl url = HttpUrl.parse(dataSpec.uri.toString());
|
@Nullable HttpUrl url = HttpUrl.parse(dataSpec.uri.toString());
|
||||||
if (url == null) {
|
if (url == null) {
|
||||||
throw new HttpDataSourceException(
|
throw new HttpDataSourceException(
|
||||||
"Malformed URL", dataSpec, HttpDataSourceException.TYPE_OPEN);
|
"Malformed URL",
|
||||||
|
dataSpec,
|
||||||
|
PlaybackException.ERROR_CODE_IO_BAD_HTTP_REQUEST,
|
||||||
|
HttpDataSourceException.TYPE_OPEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
Request.Builder builder = new Request.Builder().url(url);
|
Request.Builder builder = new Request.Builder().url(url);
|
||||||
|
@ -15,33 +15,13 @@
|
|||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.upstream;
|
package com.google.android.exoplayer2.upstream;
|
||||||
|
|
||||||
import androidx.annotation.IntDef;
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import com.google.android.exoplayer2.PlaybackException;
|
import com.google.android.exoplayer2.PlaybackException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.annotation.Documented;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
|
|
||||||
/** Used to specify reason of a DataSource error. */
|
/** Used to specify reason of a DataSource error. */
|
||||||
public class DataSourceException extends IOException {
|
public class DataSourceException extends IOException {
|
||||||
|
|
||||||
/**
|
|
||||||
* The type of operation that produced the error. One of {@link #TYPE_READ}, {@link #TYPE_OPEN}
|
|
||||||
* {@link #TYPE_CLOSE}.
|
|
||||||
*/
|
|
||||||
@Documented
|
|
||||||
@Retention(RetentionPolicy.SOURCE)
|
|
||||||
@IntDef({TYPE_OPEN, TYPE_READ, TYPE_CLOSE})
|
|
||||||
public @interface Type {}
|
|
||||||
|
|
||||||
/** The error occurred reading data from a {@link DataSource}. */
|
|
||||||
public static final int TYPE_OPEN = 1;
|
|
||||||
/** The error occurred in opening a {@link DataSource}. */
|
|
||||||
public static final int TYPE_READ = 2;
|
|
||||||
/** The error occurred in closing a {@link DataSource}. */
|
|
||||||
public static final int TYPE_CLOSE = 3;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 PlaybackException#ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE} in its
|
* {@link #reason} is {@link PlaybackException#ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE} in its
|
||||||
@ -77,19 +57,14 @@ public class DataSourceException extends IOException {
|
|||||||
*/
|
*/
|
||||||
@PlaybackException.ErrorCode public final int reason;
|
@PlaybackException.ErrorCode public final int reason;
|
||||||
|
|
||||||
/** The {@link Type} of the operation that caused the playback failure. */
|
|
||||||
@Type public final int type;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a DataSourceException with type {@link #TYPE_READ}.
|
* Constructs a DataSourceException.
|
||||||
*
|
*
|
||||||
* @deprecated Use the constructor {@link #DataSourceException(String, Throwable, int, int)}.
|
* @param reason Reason of the error, should be one of the {@code ERROR_CODE_IO_*} in {@link
|
||||||
* @param reason Reason of the error. It should only be {@link #POSITION_OUT_OF_RANGE}.
|
* PlaybackException.ErrorCode}.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
public DataSourceException(@PlaybackException.ErrorCode int reason) {
|
||||||
public DataSourceException(int reason) {
|
|
||||||
this.reason = reason;
|
this.reason = reason;
|
||||||
this.type = TYPE_READ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -99,13 +74,11 @@ public class DataSourceException extends IOException {
|
|||||||
* @param cause The error cause.
|
* @param cause The error cause.
|
||||||
* @param reason Reason of the error, should be one of the {@code ERROR_CODE_IO_*} in {@link
|
* @param reason Reason of the error, should be one of the {@code ERROR_CODE_IO_*} in {@link
|
||||||
* PlaybackException.ErrorCode}.
|
* PlaybackException.ErrorCode}.
|
||||||
* @param type See {@link Type}.
|
|
||||||
*/
|
*/
|
||||||
public DataSourceException(
|
public DataSourceException(
|
||||||
String message, Throwable cause, @PlaybackException.ErrorCode int reason, @Type int type) {
|
String message, Throwable cause, @PlaybackException.ErrorCode int reason) {
|
||||||
super(message, cause);
|
super(message, cause);
|
||||||
this.reason = reason;
|
this.reason = reason;
|
||||||
this.type = type;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -114,13 +87,10 @@ public class DataSourceException extends IOException {
|
|||||||
* @param cause The error cause.
|
* @param cause The error cause.
|
||||||
* @param reason Reason of the error, should be one of the {@code ERROR_CODE_IO_*} in {@link
|
* @param reason Reason of the error, should be one of the {@code ERROR_CODE_IO_*} in {@link
|
||||||
* PlaybackException.ErrorCode}.
|
* PlaybackException.ErrorCode}.
|
||||||
* @param type See {@link Type}.
|
|
||||||
*/
|
*/
|
||||||
public DataSourceException(
|
public DataSourceException(Throwable cause, @PlaybackException.ErrorCode int reason) {
|
||||||
Throwable cause, @PlaybackException.ErrorCode int reason, @Type int type) {
|
|
||||||
super(cause);
|
super(cause);
|
||||||
this.reason = reason;
|
this.reason = reason;
|
||||||
this.type = type;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -129,24 +99,9 @@ public class DataSourceException extends IOException {
|
|||||||
* @param message The error message.
|
* @param message The error message.
|
||||||
* @param reason Reason of the error, should be one of the {@code ERROR_CODE_IO_*} in {@link
|
* @param reason Reason of the error, should be one of the {@code ERROR_CODE_IO_*} in {@link
|
||||||
* PlaybackException.ErrorCode}.
|
* PlaybackException.ErrorCode}.
|
||||||
* @param type See {@link Type}.
|
|
||||||
*/
|
*/
|
||||||
public DataSourceException(
|
public DataSourceException(String message, @PlaybackException.ErrorCode int reason) {
|
||||||
String message, @PlaybackException.ErrorCode int reason, @Type int type) {
|
|
||||||
super(message);
|
super(message);
|
||||||
this.reason = reason;
|
this.reason = reason;
|
||||||
this.type = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a DataSourceException.
|
|
||||||
*
|
|
||||||
* @param reason Reason of the error, should be one of the {@code ERROR_CODE_IO_*} in {@link
|
|
||||||
* PlaybackException.ErrorCode}.
|
|
||||||
* @param type See {@link Type}.
|
|
||||||
*/
|
|
||||||
public DataSourceException(@PlaybackException.ErrorCode int reason, @Type int type) {
|
|
||||||
this.reason = reason;
|
|
||||||
this.type = type;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -356,7 +356,11 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou
|
|||||||
throw new CleartextNotPermittedException(e, dataSpec);
|
throw new CleartextNotPermittedException(e, dataSpec);
|
||||||
}
|
}
|
||||||
throw new HttpDataSourceException(
|
throw new HttpDataSourceException(
|
||||||
"Unable to connect", e, dataSpec, HttpDataSourceException.TYPE_OPEN);
|
"Unable to connect",
|
||||||
|
e,
|
||||||
|
dataSpec,
|
||||||
|
PlaybackException.ERROR_CODE_IO_NETWORK_CONNECTION_FAILED,
|
||||||
|
HttpDataSourceException.TYPE_OPEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpURLConnection connection = this.connection;
|
HttpURLConnection connection = this.connection;
|
||||||
@ -367,7 +371,11 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
closeConnectionQuietly();
|
closeConnectionQuietly();
|
||||||
throw new HttpDataSourceException(
|
throw new HttpDataSourceException(
|
||||||
"Unable to connect", e, dataSpec, HttpDataSourceException.TYPE_OPEN);
|
"Unable to connect",
|
||||||
|
e,
|
||||||
|
dataSpec,
|
||||||
|
PlaybackException.ERROR_CODE_IO_NETWORK_CONNECTION_FAILED,
|
||||||
|
HttpDataSourceException.TYPE_OPEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for a valid response code.
|
// Check for a valid response code.
|
||||||
@ -397,9 +405,7 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou
|
|||||||
responseCode, responseMessage, headers, dataSpec, errorResponseBody);
|
responseCode, responseMessage, headers, dataSpec, errorResponseBody);
|
||||||
if (responseCode == 416) {
|
if (responseCode == 416) {
|
||||||
exception.initCause(
|
exception.initCause(
|
||||||
new DataSourceException(
|
new DataSourceException(PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE));
|
||||||
PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE,
|
|
||||||
DataSourceException.TYPE_READ));
|
|
||||||
}
|
}
|
||||||
throw exception;
|
throw exception;
|
||||||
}
|
}
|
||||||
@ -443,7 +449,11 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou
|
|||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
closeConnectionQuietly();
|
closeConnectionQuietly();
|
||||||
throw new HttpDataSourceException(e, dataSpec, HttpDataSourceException.TYPE_OPEN);
|
throw new HttpDataSourceException(
|
||||||
|
e,
|
||||||
|
dataSpec,
|
||||||
|
PlaybackException.ERROR_CODE_IO_UNSPECIFIED,
|
||||||
|
HttpDataSourceException.TYPE_OPEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
opened = true;
|
opened = true;
|
||||||
@ -451,13 +461,17 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (!skipFully(bytesToSkip)) {
|
if (!skipFully(bytesToSkip)) {
|
||||||
throw new DataSourceException(
|
throw new DataSourceException(PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE);
|
||||||
PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE,
|
|
||||||
DataSourceException.TYPE_READ);
|
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
closeConnectionQuietly();
|
closeConnectionQuietly();
|
||||||
throw new HttpDataSourceException(e, dataSpec, HttpDataSourceException.TYPE_OPEN);
|
|
||||||
|
@PlaybackException.ErrorCode int errorCode = PlaybackException.ERROR_CODE_IO_UNSPECIFIED;
|
||||||
|
if (e instanceof DataSourceException) {
|
||||||
|
errorCode = ((DataSourceException) e).reason;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new HttpDataSourceException(e, dataSpec, errorCode, HttpDataSourceException.TYPE_OPEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
return bytesToRead;
|
return bytesToRead;
|
||||||
@ -469,7 +483,10 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou
|
|||||||
return readInternal(buffer, offset, readLength);
|
return readInternal(buffer, offset, readLength);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new HttpDataSourceException(
|
throw new HttpDataSourceException(
|
||||||
e, castNonNull(dataSpec), HttpDataSourceException.TYPE_READ);
|
e,
|
||||||
|
castNonNull(dataSpec),
|
||||||
|
PlaybackException.ERROR_CODE_IO_UNSPECIFIED,
|
||||||
|
HttpDataSourceException.TYPE_READ);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -485,7 +502,10 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou
|
|||||||
inputStream.close();
|
inputStream.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new HttpDataSourceException(
|
throw new HttpDataSourceException(
|
||||||
e, castNonNull(dataSpec), HttpDataSourceException.TYPE_CLOSE);
|
e,
|
||||||
|
castNonNull(dataSpec),
|
||||||
|
PlaybackException.ERROR_CODE_IO_UNSPECIFIED,
|
||||||
|
HttpDataSourceException.TYPE_CLOSE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -16,12 +16,16 @@
|
|||||||
package com.google.android.exoplayer2.upstream;
|
package com.google.android.exoplayer2.upstream;
|
||||||
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import androidx.annotation.IntDef;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import com.google.android.exoplayer2.PlaybackException;
|
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;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.annotation.Documented;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -187,9 +191,27 @@ public interface HttpDataSource extends DataSource {
|
|||||||
/** Thrown when an error is encountered when trying to read from a {@link HttpDataSource}. */
|
/** Thrown when an error is encountered when trying to read from a {@link HttpDataSource}. */
|
||||||
class HttpDataSourceException extends DataSourceException {
|
class HttpDataSourceException extends DataSourceException {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type of operation that produced the error. One of {@link #TYPE_READ}, {@link #TYPE_OPEN}
|
||||||
|
* {@link #TYPE_CLOSE}.
|
||||||
|
*/
|
||||||
|
@Documented
|
||||||
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
|
@IntDef({TYPE_OPEN, TYPE_READ, TYPE_CLOSE})
|
||||||
|
public @interface Type {}
|
||||||
|
|
||||||
|
/** The error occurred reading data from a {@code HttpDataSource}. */
|
||||||
|
public static final int TYPE_OPEN = 1;
|
||||||
|
/** The error occurred in opening a {@code HttpDataSource}. */
|
||||||
|
public static final int TYPE_READ = 2;
|
||||||
|
/** The error occurred in closing a {@code HttpDataSource}. */
|
||||||
|
public static final int TYPE_CLOSE = 3;
|
||||||
|
|
||||||
/** The {@link DataSpec} associated with the current connection. */
|
/** The {@link DataSpec} associated with the current connection. */
|
||||||
public final DataSpec dataSpec;
|
public final DataSpec dataSpec;
|
||||||
|
|
||||||
|
@Type public final int type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated Use {@link #HttpDataSourceException(DataSpec, int, int)
|
* @deprecated Use {@link #HttpDataSourceException(DataSpec, int, int)
|
||||||
* HttpDataSourceException(DataSpec, PlaybackException.ERROR_CODE_IO_UNSPECIFIED, int)}.
|
* HttpDataSourceException(DataSpec, PlaybackException.ERROR_CODE_IO_UNSPECIFIED, int)}.
|
||||||
@ -209,8 +231,9 @@ public interface HttpDataSource extends DataSource {
|
|||||||
*/
|
*/
|
||||||
public HttpDataSourceException(
|
public HttpDataSourceException(
|
||||||
DataSpec dataSpec, @PlaybackException.ErrorCode int errorCode, @Type int type) {
|
DataSpec dataSpec, @PlaybackException.ErrorCode int errorCode, @Type int type) {
|
||||||
super(errorCode, type);
|
super(errorCode);
|
||||||
this.dataSpec = dataSpec;
|
this.dataSpec = dataSpec;
|
||||||
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -237,8 +260,9 @@ public interface HttpDataSource extends DataSource {
|
|||||||
DataSpec dataSpec,
|
DataSpec dataSpec,
|
||||||
@PlaybackException.ErrorCode int errorCode,
|
@PlaybackException.ErrorCode int errorCode,
|
||||||
@Type int type) {
|
@Type int type) {
|
||||||
super(message, errorCode, type);
|
super(message, errorCode);
|
||||||
this.dataSpec = dataSpec;
|
this.dataSpec = dataSpec;
|
||||||
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -265,8 +289,9 @@ public interface HttpDataSource extends DataSource {
|
|||||||
DataSpec dataSpec,
|
DataSpec dataSpec,
|
||||||
@PlaybackException.ErrorCode int errorCode,
|
@PlaybackException.ErrorCode int errorCode,
|
||||||
@Type int type) {
|
@Type int type) {
|
||||||
super(cause, errorCode, type);
|
super(cause, errorCode);
|
||||||
this.dataSpec = dataSpec;
|
this.dataSpec = dataSpec;
|
||||||
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -296,8 +321,9 @@ public interface HttpDataSource extends DataSource {
|
|||||||
DataSpec dataSpec,
|
DataSpec dataSpec,
|
||||||
@PlaybackException.ErrorCode int errorCode,
|
@PlaybackException.ErrorCode int errorCode,
|
||||||
@Type int type) {
|
@Type int type) {
|
||||||
super(message, cause, errorCode, type);
|
super(message, cause, errorCode);
|
||||||
this.dataSpec = dataSpec;
|
this.dataSpec = dataSpec;
|
||||||
|
this.type = type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,26 +30,20 @@ public class DataSourceExceptionTest {
|
|||||||
@Test
|
@Test
|
||||||
public void isCausedByPositionOutOfRange_reasonIsPositionOutOfRange_returnsTrue() {
|
public void isCausedByPositionOutOfRange_reasonIsPositionOutOfRange_returnsTrue() {
|
||||||
DataSourceException e =
|
DataSourceException e =
|
||||||
new DataSourceException(
|
new DataSourceException(PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE);
|
||||||
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 =
|
DataSourceException e = new DataSourceException(PlaybackException.ERROR_CODE_IO_UNSPECIFIED);
|
||||||
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_indirectCauseReasonIsPositionOutOfRange_returnsTrue() {
|
||||||
DataSourceException cause =
|
DataSourceException cause =
|
||||||
new DataSourceException(
|
new DataSourceException(PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE);
|
||||||
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();
|
||||||
}
|
}
|
||||||
@ -57,8 +51,7 @@ public class DataSourceExceptionTest {
|
|||||||
@Test
|
@Test
|
||||||
public void isCausedByPositionOutOfRange_causeReasonIsOther_returnsFalse() {
|
public void isCausedByPositionOutOfRange_causeReasonIsOther_returnsFalse() {
|
||||||
DataSourceException cause =
|
DataSourceException cause =
|
||||||
new DataSourceException(
|
new DataSourceException(PlaybackException.ERROR_CODE_IO_UNSPECIFIED);
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
@ -32,10 +32,22 @@ import java.io.InputStream;
|
|||||||
public final class AssetDataSource extends BaseDataSource {
|
public final class AssetDataSource extends BaseDataSource {
|
||||||
|
|
||||||
/** Thrown when an {@link IOException} is encountered reading a local asset. */
|
/** Thrown when an {@link IOException} is encountered reading a local asset. */
|
||||||
public static final class AssetDataSourceException extends IOException {
|
public static final class AssetDataSourceException extends DataSourceException {
|
||||||
|
|
||||||
|
/** @deprecated Use {@link #AssetDataSourceException(Throwable, int)}. */
|
||||||
|
@Deprecated
|
||||||
public AssetDataSourceException(IOException cause) {
|
public AssetDataSourceException(IOException cause) {
|
||||||
super(cause);
|
super(cause, PlaybackException.ERROR_CODE_IO_UNSPECIFIED);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance.
|
||||||
|
*
|
||||||
|
* @param cause The error cause.
|
||||||
|
* @param errorCode See {@link PlaybackException.ErrorCode}.
|
||||||
|
*/
|
||||||
|
public AssetDataSourceException(Throwable cause, @PlaybackException.ErrorCode int errorCode) {
|
||||||
|
super(cause, errorCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,9 +80,7 @@ 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(
|
throw new DataSourceException(PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE);
|
||||||
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;
|
||||||
@ -84,7 +94,7 @@ public final class AssetDataSource extends BaseDataSource {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new AssetDataSourceException(e);
|
throw new AssetDataSourceException(e, PlaybackException.ERROR_CODE_IO_UNSPECIFIED);
|
||||||
}
|
}
|
||||||
|
|
||||||
opened = true;
|
opened = true;
|
||||||
@ -106,7 +116,7 @@ public final class AssetDataSource extends BaseDataSource {
|
|||||||
bytesRemaining == C.LENGTH_UNSET ? readLength : (int) min(bytesRemaining, readLength);
|
bytesRemaining == C.LENGTH_UNSET ? readLength : (int) min(bytesRemaining, readLength);
|
||||||
bytesRead = castNonNull(inputStream).read(buffer, offset, bytesToRead);
|
bytesRead = castNonNull(inputStream).read(buffer, offset, bytesToRead);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new AssetDataSourceException(e);
|
throw new AssetDataSourceException(e, PlaybackException.ERROR_CODE_IO_UNSPECIFIED);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bytesRead == -1) {
|
if (bytesRead == -1) {
|
||||||
@ -133,7 +143,7 @@ public final class AssetDataSource extends BaseDataSource {
|
|||||||
inputStream.close();
|
inputStream.close();
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new AssetDataSourceException(e);
|
throw new AssetDataSourceException(e, PlaybackException.ERROR_CODE_IO_UNSPECIFIED);
|
||||||
} finally {
|
} finally {
|
||||||
inputStream = null;
|
inputStream = null;
|
||||||
if (opened) {
|
if (opened) {
|
||||||
|
@ -47,9 +47,7 @@ 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(
|
throw new DataSourceException(PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE);
|
||||||
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;
|
||||||
|
@ -34,10 +34,23 @@ import java.nio.channels.FileChannel;
|
|||||||
public final class ContentDataSource extends BaseDataSource {
|
public final class ContentDataSource extends BaseDataSource {
|
||||||
|
|
||||||
/** Thrown when an {@link IOException} is encountered reading from a content URI. */
|
/** Thrown when an {@link IOException} is encountered reading from a content URI. */
|
||||||
public static class ContentDataSourceException extends IOException {
|
public static class ContentDataSourceException extends DataSourceException {
|
||||||
|
|
||||||
|
/** @deprecated Use {@link #ContentDataSourceException(IOException, int)}. */
|
||||||
|
@Deprecated
|
||||||
public ContentDataSourceException(IOException cause) {
|
public ContentDataSourceException(IOException cause) {
|
||||||
super(cause);
|
super(cause, PlaybackException.ERROR_CODE_IO_UNSPECIFIED);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance.
|
||||||
|
*
|
||||||
|
* @param cause The error cause.
|
||||||
|
* @param errorCode See {@link PlaybackException.ErrorCode}.
|
||||||
|
*/
|
||||||
|
public ContentDataSourceException(
|
||||||
|
IOException cause, @PlaybackException.ErrorCode int errorCode) {
|
||||||
|
super(cause, errorCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,9 +93,7 @@ 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(
|
throw new DataSourceException(PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE);
|
||||||
PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE,
|
|
||||||
DataSourceException.TYPE_READ);
|
|
||||||
}
|
}
|
||||||
long assetFileDescriptorOffset = assetFileDescriptor.getStartOffset();
|
long assetFileDescriptorOffset = assetFileDescriptor.getStartOffset();
|
||||||
long skipped =
|
long skipped =
|
||||||
@ -91,9 +102,7 @@ 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(
|
throw new DataSourceException(PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE);
|
||||||
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
|
||||||
@ -107,20 +116,17 @@ public final class ContentDataSource extends BaseDataSource {
|
|||||||
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(
|
throw new DataSourceException(
|
||||||
PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE,
|
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(
|
throw new DataSourceException(PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE);
|
||||||
PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE,
|
|
||||||
DataSourceException.TYPE_READ);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new ContentDataSourceException(e);
|
throw new ContentDataSourceException(e, PlaybackException.ERROR_CODE_IO_UNSPECIFIED);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dataSpec.length != C.LENGTH_UNSET) {
|
if (dataSpec.length != C.LENGTH_UNSET) {
|
||||||
@ -146,7 +152,7 @@ public final class ContentDataSource extends BaseDataSource {
|
|||||||
bytesRemaining == C.LENGTH_UNSET ? readLength : (int) min(bytesRemaining, readLength);
|
bytesRemaining == C.LENGTH_UNSET ? readLength : (int) min(bytesRemaining, readLength);
|
||||||
bytesRead = castNonNull(inputStream).read(buffer, offset, bytesToRead);
|
bytesRead = castNonNull(inputStream).read(buffer, offset, bytesToRead);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new ContentDataSourceException(e);
|
throw new ContentDataSourceException(e, PlaybackException.ERROR_CODE_IO_UNSPECIFIED);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bytesRead == -1) {
|
if (bytesRead == -1) {
|
||||||
@ -174,7 +180,7 @@ public final class ContentDataSource extends BaseDataSource {
|
|||||||
inputStream.close();
|
inputStream.close();
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new ContentDataSourceException(e);
|
throw new ContentDataSourceException(e, PlaybackException.ERROR_CODE_IO_UNSPECIFIED);
|
||||||
} finally {
|
} finally {
|
||||||
inputStream = null;
|
inputStream = null;
|
||||||
try {
|
try {
|
||||||
@ -182,7 +188,7 @@ public final class ContentDataSource extends BaseDataSource {
|
|||||||
assetFileDescriptor.close();
|
assetFileDescriptor.close();
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new ContentDataSourceException(e);
|
throw new ContentDataSourceException(e, PlaybackException.ERROR_CODE_IO_UNSPECIFIED);
|
||||||
} finally {
|
} finally {
|
||||||
assetFileDescriptor = null;
|
assetFileDescriptor = null;
|
||||||
if (opened) {
|
if (opened) {
|
||||||
|
@ -70,9 +70,7 @@ public final class DataSchemeDataSource extends BaseDataSource {
|
|||||||
}
|
}
|
||||||
if (dataSpec.position > data.length) {
|
if (dataSpec.position > data.length) {
|
||||||
data = null;
|
data = null;
|
||||||
throw new DataSourceException(
|
throw new DataSourceException(PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE);
|
||||||
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;
|
||||||
|
@ -91,9 +91,7 @@ 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(
|
throw new DataSourceException(PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE);
|
||||||
PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE,
|
|
||||||
DataSourceException.TYPE_READ);
|
|
||||||
}
|
}
|
||||||
} catch (FileDataSourceException e) {
|
} catch (FileDataSourceException e) {
|
||||||
throw e;
|
throw e;
|
||||||
|
@ -55,13 +55,38 @@ import java.nio.channels.FileChannel;
|
|||||||
public final class RawResourceDataSource extends BaseDataSource {
|
public final class RawResourceDataSource extends BaseDataSource {
|
||||||
|
|
||||||
/** Thrown when an {@link IOException} is encountered reading from a raw resource. */
|
/** Thrown when an {@link IOException} is encountered reading from a raw resource. */
|
||||||
public static class RawResourceDataSourceException extends IOException {
|
public static class RawResourceDataSourceException extends DataSourceException {
|
||||||
|
/** @deprecated Use {@link #RawResourceDataSourceException(String, int)}. */
|
||||||
|
@Deprecated
|
||||||
public RawResourceDataSourceException(String message) {
|
public RawResourceDataSourceException(String message) {
|
||||||
super(message);
|
super(message, PlaybackException.ERROR_CODE_IO_UNSPECIFIED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance.
|
||||||
|
*
|
||||||
|
* @param message The error message.
|
||||||
|
* @param errorCode See {@link PlaybackException.ErrorCode}.
|
||||||
|
*/
|
||||||
|
public RawResourceDataSourceException(
|
||||||
|
String message, @PlaybackException.ErrorCode int errorCode) {
|
||||||
|
super(message, errorCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @deprecated Use {@link #RawResourceDataSourceException(Throwable, int)}. */
|
||||||
|
@Deprecated
|
||||||
public RawResourceDataSourceException(Throwable e) {
|
public RawResourceDataSourceException(Throwable e) {
|
||||||
super(e);
|
super(e, PlaybackException.ERROR_CODE_IO_UNSPECIFIED);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance.
|
||||||
|
*
|
||||||
|
* @param e The error cause.
|
||||||
|
* @param errorCode See {@link PlaybackException.ErrorCode}.
|
||||||
|
*/
|
||||||
|
public RawResourceDataSourceException(Throwable e, @PlaybackException.ErrorCode int errorCode) {
|
||||||
|
super(e, errorCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,7 +132,9 @@ public final class RawResourceDataSource extends BaseDataSource {
|
|||||||
try {
|
try {
|
||||||
resourceId = Integer.parseInt(Assertions.checkNotNull(uri.getLastPathSegment()));
|
resourceId = Integer.parseInt(Assertions.checkNotNull(uri.getLastPathSegment()));
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
throw new RawResourceDataSourceException("Resource identifier must be an integer.");
|
throw new RawResourceDataSourceException(
|
||||||
|
"Resource identifier must be an integer.",
|
||||||
|
PlaybackException.ERROR_CODE_IO_FILE_NOT_FOUND);
|
||||||
}
|
}
|
||||||
} else if (TextUtils.equals(ContentResolver.SCHEME_ANDROID_RESOURCE, uri.getScheme())) {
|
} else if (TextUtils.equals(ContentResolver.SCHEME_ANDROID_RESOURCE, uri.getScheme())) {
|
||||||
String path = Assertions.checkNotNull(uri.getPath());
|
String path = Assertions.checkNotNull(uri.getPath());
|
||||||
@ -120,14 +147,16 @@ public final class RawResourceDataSource extends BaseDataSource {
|
|||||||
resources.getIdentifier(
|
resources.getIdentifier(
|
||||||
resourceName, /* defType= */ "raw", /* defPackage= */ packageName);
|
resourceName, /* defType= */ "raw", /* defPackage= */ packageName);
|
||||||
if (resourceId == 0) {
|
if (resourceId == 0) {
|
||||||
throw new RawResourceDataSourceException("Resource not found.");
|
throw new RawResourceDataSourceException(
|
||||||
|
"Resource not found.", PlaybackException.ERROR_CODE_IO_FILE_NOT_FOUND);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new RawResourceDataSourceException(
|
throw new RawResourceDataSourceException(
|
||||||
"URI must either use scheme "
|
"URI must either use scheme "
|
||||||
+ RAW_RESOURCE_SCHEME
|
+ RAW_RESOURCE_SCHEME
|
||||||
+ " or "
|
+ " or "
|
||||||
+ ContentResolver.SCHEME_ANDROID_RESOURCE);
|
+ ContentResolver.SCHEME_ANDROID_RESOURCE,
|
||||||
|
PlaybackException.ERROR_CODE_IO_FILE_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
transferInitializing(dataSpec);
|
transferInitializing(dataSpec);
|
||||||
@ -136,12 +165,13 @@ public final class RawResourceDataSource extends BaseDataSource {
|
|||||||
try {
|
try {
|
||||||
assetFileDescriptor = resources.openRawResourceFd(resourceId);
|
assetFileDescriptor = resources.openRawResourceFd(resourceId);
|
||||||
} catch (Resources.NotFoundException e) {
|
} catch (Resources.NotFoundException e) {
|
||||||
throw new RawResourceDataSourceException(e);
|
throw new RawResourceDataSourceException(e, PlaybackException.ERROR_CODE_IO_FILE_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.assetFileDescriptor = assetFileDescriptor;
|
this.assetFileDescriptor = assetFileDescriptor;
|
||||||
if (assetFileDescriptor == null) {
|
if (assetFileDescriptor == null) {
|
||||||
throw new RawResourceDataSourceException("Resource is compressed: " + uri);
|
throw new RawResourceDataSourceException(
|
||||||
|
"Resource is compressed: " + uri, PlaybackException.ERROR_CODE_IO_UNSPECIFIED);
|
||||||
}
|
}
|
||||||
|
|
||||||
long assetFileDescriptorLength = assetFileDescriptor.getLength();
|
long assetFileDescriptorLength = assetFileDescriptor.getLength();
|
||||||
@ -157,9 +187,7 @@ 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(
|
throw new DataSourceException(PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE);
|
||||||
PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE,
|
|
||||||
DataSourceException.TYPE_READ);
|
|
||||||
}
|
}
|
||||||
long assetFileDescriptorOffset = assetFileDescriptor.getStartOffset();
|
long assetFileDescriptorOffset = assetFileDescriptor.getStartOffset();
|
||||||
long skipped =
|
long skipped =
|
||||||
@ -168,9 +196,7 @@ 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(
|
throw new DataSourceException(PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE);
|
||||||
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
|
||||||
@ -183,20 +209,17 @@ public final class RawResourceDataSource extends BaseDataSource {
|
|||||||
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(
|
throw new DataSourceException(
|
||||||
PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE,
|
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(
|
throw new DataSourceException(PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE);
|
||||||
PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE,
|
|
||||||
DataSourceException.TYPE_READ);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RawResourceDataSourceException(e);
|
throw new RawResourceDataSourceException(e, PlaybackException.ERROR_CODE_IO_UNSPECIFIED);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dataSpec.length != C.LENGTH_UNSET) {
|
if (dataSpec.length != C.LENGTH_UNSET) {
|
||||||
@ -222,13 +245,14 @@ public final class RawResourceDataSource extends BaseDataSource {
|
|||||||
bytesRemaining == C.LENGTH_UNSET ? readLength : (int) min(bytesRemaining, readLength);
|
bytesRemaining == C.LENGTH_UNSET ? readLength : (int) min(bytesRemaining, readLength);
|
||||||
bytesRead = castNonNull(inputStream).read(buffer, offset, bytesToRead);
|
bytesRead = castNonNull(inputStream).read(buffer, offset, bytesToRead);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RawResourceDataSourceException(e);
|
throw new RawResourceDataSourceException(e, PlaybackException.ERROR_CODE_IO_UNSPECIFIED);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bytesRead == -1) {
|
if (bytesRead == -1) {
|
||||||
if (bytesRemaining != C.LENGTH_UNSET) {
|
if (bytesRemaining != C.LENGTH_UNSET) {
|
||||||
// End of stream reached having not read sufficient data.
|
// End of stream reached having not read sufficient data.
|
||||||
throw new RawResourceDataSourceException(new EOFException());
|
throw new RawResourceDataSourceException(
|
||||||
|
new EOFException(), PlaybackException.ERROR_CODE_IO_UNSPECIFIED);
|
||||||
}
|
}
|
||||||
return C.RESULT_END_OF_INPUT;
|
return C.RESULT_END_OF_INPUT;
|
||||||
}
|
}
|
||||||
@ -254,7 +278,7 @@ public final class RawResourceDataSource extends BaseDataSource {
|
|||||||
inputStream.close();
|
inputStream.close();
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RawResourceDataSourceException(e);
|
throw new RawResourceDataSourceException(e, PlaybackException.ERROR_CODE_IO_UNSPECIFIED);
|
||||||
} finally {
|
} finally {
|
||||||
inputStream = null;
|
inputStream = null;
|
||||||
try {
|
try {
|
||||||
@ -262,7 +286,7 @@ public final class RawResourceDataSource extends BaseDataSource {
|
|||||||
assetFileDescriptor.close();
|
assetFileDescriptor.close();
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RawResourceDataSourceException(e);
|
throw new RawResourceDataSourceException(e, PlaybackException.ERROR_CODE_IO_UNSPECIFIED);
|
||||||
} finally {
|
} finally {
|
||||||
assetFileDescriptor = null;
|
assetFileDescriptor = null;
|
||||||
if (opened) {
|
if (opened) {
|
||||||
|
@ -575,8 +575,7 @@ public final class CacheDataSource implements DataSource {
|
|||||||
bytesRemaining -= dataSpec.position;
|
bytesRemaining -= dataSpec.position;
|
||||||
if (bytesRemaining < 0) {
|
if (bytesRemaining < 0) {
|
||||||
throw new DataSourceException(
|
throw new DataSourceException(
|
||||||
PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE,
|
PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE);
|
||||||
DataSourceException.TYPE_READ);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,9 +117,7 @@ public class FakeDataSource extends BaseDataSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (dataSpec.position > totalLength) {
|
if (dataSpec.position > totalLength) {
|
||||||
throw new DataSourceException(
|
throw new DataSourceException(PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE);
|
||||||
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