DataSource
public interface DataSource extends DataReader
AesCipherDataSource |
A |
BaseDataSource |
Base |
CacheDataSource |
A |
DefaultDataSource |
A |
HttpDataSource |
An HTTP |
PlaceholderDataSource |
A DataSource which provides no data. |
PriorityDataSource |
A |
ResolvingDataSource |
|
StatsDataSource |
|
TeeDataSource |
Tees data into a |
AssetDataSource |
A |
ByteArrayDataSource |
A |
ContentDataSource |
A |
CronetDataSource |
DataSource without intermediate buffer based on Cronet API set using UrlRequest. |
DataSchemeDataSource |
A |
DefaultHttpDataSource |
An |
FakeDataSource |
A fake |
FileDataSource |
A |
FileDescriptorDataSource |
A |
HttpEngineDataSource |
DataSource without intermediate buffer based on |
MediaDataSourceAdapter |
A |
OkHttpDataSource |
An |
RawResourceDataSource |
A |
RtmpDataSource |
A Real-Time Messaging Protocol (RTMP) |
UdpDataSource |
A UDP |
Reads data from URI-identified resources.
Summary
Nested types |
|---|
public interface DataSource.FactoryA factory for |
Public methods |
|
|---|---|
abstract void |
@UnstableApiAdds a |
abstract void |
Closes the source. |
default Map<String, List<String>> |
When the source is open, returns the response headers associated with the last |
abstract @Nullable Uri |
When the source is open, returns the |
abstract long |
@UnstableApiOpens the source to read the specified data. |
Inherited methods |
||
|---|---|---|
|
Public methods
addTransferListener
@UnstableApi
abstract void addTransferListener(TransferListener transferListener)
Adds a TransferListener to listen to data transfers. This method is not thread-safe.
| Parameters | |
|---|---|
TransferListener transferListener |
close
@UnstableApi
abstract void close()
Closes the source. This method must be called even if the corresponding call to open threw an IOException.
| Throws | |
|---|---|
java.io.IOException |
If an error occurs closing the source. |
getResponseHeaders
@UnstableApi
default Map<String, List<String>> getResponseHeaders()
When the source is open, returns the response headers associated with the last open call. Otherwise, returns an empty map.
Key look-up in the returned map is case-insensitive.
getUri
@UnstableApi
abstract @Nullable Uri getUri()
When the source is open, returns the Uri from which data is being read. The returned Uri will be identical to the one passed open in the DataSpec unless redirection has occurred. If redirection has occurred, the Uri after redirection is returned.
open
@UnstableApi
abstract long open(DataSpec dataSpec)
Opens the source to read the specified data. If an IOException is thrown, callers must still call close to ensure that any partial effects of the invocation are cleaned up.
The following edge case behaviors apply:
- If the
requested positionis within the resource, but therequested lengthextends beyond the end of the resource, thenopenwill succeed and data from the requested position to the end of the resource will be made available throughread. - If the
requested positionis equal to the length of the resource, thenopenwill succeed, andreadwill immediately returnRESULT_END_OF_INPUT. - If the
requested positionis greater than the length of the resource, thenopenwill throw anIOExceptionfor whichisCausedByPositionOutOfRangewill betrue.
| Parameters | |
|---|---|
DataSpec dataSpec |
Defines the data to be read. |
| Returns | |
|---|---|
long |
The number of bytes that can be read from the opened source. For unbounded requests (i.e., requests where |
| Throws | |
|---|---|
java.io.IOException |
If an error occurs opening the source. |