public final class AssetDataSource extends Object implements UriDataSource
UriDataSource.| Modifier and Type | Class and Description |
|---|---|
static class |
AssetDataSource.AssetDataSourceException
Thrown when an
IOException is encountered reading a local asset. |
| Constructor and Description |
|---|
AssetDataSource(Context context)
Constructs a new
DataSource that retrieves data from a local asset. |
AssetDataSource(Context context,
TransferListener listener)
Constructs a new
DataSource that retrieves data from a local asset. |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the
DataSource. |
String |
getUri()
When the source is open, returns the URI from which data is being read.
|
long |
open(DataSpec dataSpec)
Opens the
DataSource to read the specified data. |
int |
read(byte[] buffer,
int offset,
int readLength)
Reads up to
length bytes of data and stores them into buffer, starting at
index offset. |
public AssetDataSource(Context context)
DataSource that retrieves data from a local asset.public AssetDataSource(Context context, TransferListener listener)
DataSource that retrieves data from a local asset.listener - An optional listener. Specify null for no listener.public long open(DataSpec dataSpec) throws AssetDataSource.AssetDataSourceException
DataSourceDataSource to read the specified data. Calls to DataSource.open(DataSpec) and
DataSource.close() must be balanced.
Note: If DataSource.open(DataSpec) throws an IOException, callers must still call
DataSource.close() to ensure that any partial effects of the DataSource.open(DataSpec) invocation
are cleaned up. Implementations of this class can assume that callers will call
DataSource.close() in this case.
open in interface DataSourcedataSpec - Defines the data to be read.DataSpec.length equals C.LENGTH_UNBOUNDED) this value
is the resolved length of the request, or C.LENGTH_UNBOUNDED if the length is still
unresolved. For all other requests, the value returned will be equal to the request's
DataSpec.length.AssetDataSource.AssetDataSourceExceptionpublic int read(byte[] buffer,
int offset,
int readLength)
throws AssetDataSource.AssetDataSourceException
DataSourcelength bytes of data and stores them into buffer, starting at
index offset.
This method blocks until at least one byte of data can be read, the end of the opened range is detected, or an exception is thrown.
read in interface DataSourcebuffer - The buffer into which the read data should be stored.offset - The start offset into buffer at which data should be written.readLength - The maximum number of bytes to read.C.RESULT_END_OF_INPUT if the end of the opened
range is reached.AssetDataSource.AssetDataSourceExceptionpublic String getUri()
UriDataSourceIf redirection occurred, the URI after redirection is the one returned.
getUri in interface UriDataSourcepublic void close()
throws AssetDataSource.AssetDataSourceException
DataSourceDataSource.
Note: This method will be called even if the corresponding call to DataSource.open(DataSpec)
threw an IOException. See DataSource.open(DataSpec) for more details.
close in interface DataSourceAssetDataSource.AssetDataSourceException