Simplify FileDataSource exception management
And change one IO_UNSPECIFIED for a ERROR_CODE_FAILED_RUNTIME_CHECK. PiperOrigin-RevId: 387772253
This commit is contained in:
parent
e65bcefad1
commit
c45d54726f
@ -58,7 +58,9 @@ public final class FileDataSource extends BaseDataSource {
|
|||||||
|
|
||||||
/** Creates a {@code FileDataSourceException}. */
|
/** Creates a {@code FileDataSourceException}. */
|
||||||
public FileDataSourceException(
|
public FileDataSourceException(
|
||||||
String message, Throwable cause, @PlaybackException.ErrorCode int errorCode) {
|
@Nullable String message,
|
||||||
|
@Nullable Throwable cause,
|
||||||
|
@PlaybackException.ErrorCode int errorCode) {
|
||||||
super(message, cause, errorCode);
|
super(message, cause, errorCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -100,26 +102,23 @@ public final class FileDataSource extends BaseDataSource {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long open(DataSpec dataSpec) throws FileDataSourceException {
|
public long open(DataSpec dataSpec) throws FileDataSourceException {
|
||||||
|
Uri uri = dataSpec.uri;
|
||||||
|
this.uri = uri;
|
||||||
|
transferInitializing(dataSpec);
|
||||||
|
this.file = openLocalFile(uri);
|
||||||
try {
|
try {
|
||||||
Uri uri = dataSpec.uri;
|
|
||||||
this.uri = uri;
|
|
||||||
|
|
||||||
transferInitializing(dataSpec);
|
|
||||||
|
|
||||||
this.file = openLocalFile(uri);
|
|
||||||
file.seek(dataSpec.position);
|
file.seek(dataSpec.position);
|
||||||
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) {
|
} catch (IOException e) {
|
||||||
throw new DataSourceException(PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE);
|
|
||||||
}
|
|
||||||
} catch (FileDataSourceException e) {
|
|
||||||
throw e;
|
|
||||||
} catch (DataSourceException e) {
|
|
||||||
throw new FileDataSourceException(e, e.reason);
|
|
||||||
} catch (IOException | RuntimeException e) {
|
|
||||||
throw new FileDataSourceException(e, PlaybackException.ERROR_CODE_IO_UNSPECIFIED);
|
throw new FileDataSourceException(e, PlaybackException.ERROR_CODE_IO_UNSPECIFIED);
|
||||||
}
|
}
|
||||||
|
if (bytesRemaining < 0) {
|
||||||
|
throw new FileDataSourceException(
|
||||||
|
/* message= */ null,
|
||||||
|
/* cause= */ null,
|
||||||
|
PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE);
|
||||||
|
}
|
||||||
|
|
||||||
opened = true;
|
opened = true;
|
||||||
transferStarted(dataSpec);
|
transferStarted(dataSpec);
|
||||||
@ -186,7 +185,7 @@ public final class FileDataSource extends BaseDataSource {
|
|||||||
+ " avoid this. path=%s,query=%s,fragment=%s",
|
+ " avoid this. path=%s,query=%s,fragment=%s",
|
||||||
uri.getPath(), uri.getQuery(), uri.getFragment()),
|
uri.getPath(), uri.getQuery(), uri.getFragment()),
|
||||||
e,
|
e,
|
||||||
PlaybackException.ERROR_CODE_IO_UNSPECIFIED);
|
PlaybackException.ERROR_CODE_FAILED_RUNTIME_CHECK);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(internal b/193503588): Add tests to ensure the correct error codes are assigned under
|
// TODO(internal b/193503588): Add tests to ensure the correct error codes are assigned under
|
||||||
|
Loading…
x
Reference in New Issue
Block a user