public final class DataSpec
extends java.lang.Object
| 限定符和类型 | 类和说明 |
|---|---|
static class |
DataSpec.Builder
Builds
DataSpec instances. |
static interface |
DataSpec.Flags
The flags that apply to any request for data.
|
static interface |
DataSpec.HttpMethod
HTTP methods supported by ExoPlayer
HttpDataSources. |
| 限定符和类型 | 字段和说明 |
|---|---|
long |
absoluteStreamPosition
已过时。
Use
position except for specific use cases where the absolute position
within the resource is required within a DataSource chain. Where the absolute
position is required, use uriPositionOffset + position. |
java.lang.Object |
customData
Application specific data.
|
static int |
FLAG_ALLOW_CACHE_FRAGMENTATION
Allows fragmentation of this request into multiple cache files, meaning a cache eviction policy
will be able to evict individual fragments of the data.
|
static int |
FLAG_ALLOW_GZIP
Allows an underlying network stack to request that the server use gzip compression.
|
static int |
FLAG_DONT_CACHE_IF_LENGTH_UNKNOWN
Prevents caching if the length cannot be resolved when the
DataSource is opened. |
static int |
FLAG_MIGHT_NOT_USE_FULL_NETWORK_SPEED
Indicates there are known external factors that might prevent the data from being loaded at
full network speed (e.g. server throttling or unfinished live media chunks).
|
int |
flags
Request
flags. |
static int |
HTTP_METHOD_GET
HTTP GET method.
|
static int |
HTTP_METHOD_HEAD
HTTP HEAD method.
|
static int |
HTTP_METHOD_POST
HTTP POST method.
|
byte[] |
httpBody
The HTTP request body, null otherwise.
|
int |
httpMethod
The HTTP method to use when requesting the data.
|
java.util.Map<java.lang.String,java.lang.String> |
httpRequestHeaders
Additional HTTP headers to use when requesting the data.
|
java.lang.String |
key
A key that uniquely identifies the resource.
|
long |
length
The length of the data, or
C.LENGTH_UNSET. |
long |
position
The position of the data when read from
uri. |
android.net.Uri |
uri
A
Uri from which data belonging to the resource can be read. |
long |
uriPositionOffset
The offset of the data located at
uri within the resource. |
| 构造器和说明 |
|---|
DataSpec(android.net.Uri uri)
Constructs an instance.
|
DataSpec(android.net.Uri uri,
byte[] postBody,
long absoluteStreamPosition,
long position,
long length,
java.lang.String key,
int flags)
已过时。
Use
DataSpec.Builder. Note that the httpMethod must be set explicitly for the
Builder. |
DataSpec(android.net.Uri uri,
int flags)
已过时。
Use
DataSpec.Builder. |
DataSpec(android.net.Uri uri,
int httpMethod,
byte[] httpBody,
long absoluteStreamPosition,
long position,
long length,
java.lang.String key,
int flags)
已过时。
Use
DataSpec.Builder. |
DataSpec(android.net.Uri uri,
int httpMethod,
byte[] httpBody,
long absoluteStreamPosition,
long position,
long length,
java.lang.String key,
int flags,
java.util.Map<java.lang.String,java.lang.String> httpRequestHeaders)
已过时。
Use
DataSpec.Builder. |
DataSpec(android.net.Uri uri,
long position,
long length)
Constructs an instance.
|
DataSpec(android.net.Uri uri,
long absoluteStreamPosition,
long position,
long length,
java.lang.String key,
int flags)
已过时。
Use
DataSpec.Builder. |
DataSpec(android.net.Uri uri,
long position,
long length,
java.lang.String key)
已过时。
Use
DataSpec.Builder. |
DataSpec(android.net.Uri uri,
long position,
long length,
java.lang.String key,
int flags)
已过时。
Use
DataSpec.Builder. |
DataSpec(android.net.Uri uri,
long position,
long length,
java.lang.String key,
int flags,
java.util.Map<java.lang.String,java.lang.String> httpRequestHeaders)
已过时。
Use
DataSpec.Builder. |
| 限定符和类型 | 方法和说明 |
|---|---|
DataSpec.Builder |
buildUpon()
Returns a
DataSpec.Builder initialized with the values of this instance. |
java.lang.String |
getHttpMethodString()
Returns the uppercase HTTP method name (e.g., "GET", "POST", "HEAD") corresponding to the
httpMethod. |
static java.lang.String |
getStringForHttpMethod(int httpMethod)
Returns an uppercase HTTP method name (e.g., "GET", "POST", "HEAD") corresponding to the given
DataSpec.HttpMethod. |
boolean |
isFlagSet(int flag)
Returns whether the given flag is set.
|
DataSpec |
subrange(long offset)
Returns a data spec that represents a subrange of the data defined by this DataSpec.
|
DataSpec |
subrange(long offset,
long length)
Returns a data spec that represents a subrange of the data defined by this DataSpec.
|
java.lang.String |
toString() |
DataSpec |
withAdditionalHeaders(java.util.Map<java.lang.String,java.lang.String> additionalHttpRequestHeaders)
Returns a copy this data spec with additional HTTP request headers.
|
DataSpec |
withRequestHeaders(java.util.Map<java.lang.String,java.lang.String> httpRequestHeaders)
Returns a copy of this data spec with the specified HTTP request headers.
|
DataSpec |
withUri(android.net.Uri uri)
Returns a copy of this data spec with the specified Uri.
|
public static final int FLAG_ALLOW_GZIP
Should not typically be set if the data being requested is already compressed (e.g. most audio and video requests). May be set when requesting other data.
When a DataSource is used to request data with this flag set, and if the DataSource does make a network request, then the value returned from DataSource.open(DataSpec) will typically be C.LENGTH_UNSET. The data read from DataReader.read(byte[], int, int) will be the decompressed data.
public static final int FLAG_DONT_CACHE_IF_LENGTH_UNKNOWN
DataSource is opened.public static final int FLAG_ALLOW_CACHE_FRAGMENTATION
public static final int FLAG_MIGHT_NOT_USE_FULL_NETWORK_SPEED
public static final int HTTP_METHOD_GET
public static final int HTTP_METHOD_POST
public static final int HTTP_METHOD_HEAD
public final android.net.Uri uri
Uri from which data belonging to the resource can be read.public final long uriPositionOffset
uri within the resource.
Equal to 0 unless uri provides access to a subset of the resource. As an example,
consider a resource that can be requested over the network and is 1000 bytes long. If uri points to a local file that contains just bytes [200-300], then this field will be set to
200.
This field can be ignored except for in specific circumstances where the absolute position
in the resource is required in a DataSource chain. One example is when a DataSource needs to decrypt the content as it's read. In this case the absolute position in
the resource is typically needed to correctly initialize the decryption algorithm.
@DataSpec.HttpMethod public final int httpMethod
DataSource implementations.public final byte[] httpBody
httpBody.length
will be non-zero.public final java.util.Map<java.lang.String,java.lang.String> httpRequestHeaders
Note: This map is for additional headers specific to the data being requested. It does not
include headers that are set directly by HttpDataSource implementations. In particular,
this means the following headers are not included:
Range: HttpDataSource implementations derive the Range header
from position and length.
Accept-Encoding: HttpDataSource implementations derive the Accept-Encoding header based on whether flags includes FLAG_ALLOW_GZIP.
User-Agent: HttpDataSource implementations set the User-Agent
header directly.
HttpDataSource layer. I.e., headers set using HttpDataSource.setRequestProperty(String, String), and using HttpDataSource.Factory.setDefaultRequestProperties(Map).
@Deprecated public final long absoluteStreamPosition
position except for specific use cases where the absolute position
within the resource is required within a DataSource chain. Where the absolute
position is required, use uriPositionOffset + position.public final long position
uri.public final long length
C.LENGTH_UNSET.public final java.lang.String key
@DataSpec.Flags public final int flags
flags.public final java.lang.Object customData
This field is intended for advanced use cases in which applications require the ability to
attach custom data to DataSpec instances. The custom data should be immutable.
public DataSpec(android.net.Uri uri)
uri - uri.public DataSpec(android.net.Uri uri,
long position,
long length)
@Deprecated
public DataSpec(android.net.Uri uri,
@DataSpec.Flags
int flags)
DataSpec.Builder.@Deprecated
public DataSpec(android.net.Uri uri,
long position,
long length,
java.lang.String key)
DataSpec.Builder.@Deprecated
public DataSpec(android.net.Uri uri,
long position,
long length,
java.lang.String key,
@DataSpec.Flags
int flags)
DataSpec.Builder.@Deprecated
public DataSpec(android.net.Uri uri,
long position,
long length,
java.lang.String key,
@DataSpec.Flags
int flags,
java.util.Map<java.lang.String,java.lang.String> httpRequestHeaders)
DataSpec.Builder.@Deprecated
public DataSpec(android.net.Uri uri,
long absoluteStreamPosition,
long position,
long length,
java.lang.String key,
@DataSpec.Flags
int flags)
DataSpec.Builder.uriPositionOffset may be non-zero.@Deprecated
public DataSpec(android.net.Uri uri,
byte[] postBody,
long absoluteStreamPosition,
long position,
long length,
java.lang.String key,
@DataSpec.Flags
int flags)
DataSpec.Builder. Note that the httpMethod must be set explicitly for the
Builder.uriPositionOffset may be non-zero. The httpMethod
is inferred from postBody. If postBody is non-null then httpMethod is
set to HTTP_METHOD_POST. If postBody is null then httpMethod is set
to HTTP_METHOD_GET.uri - uri.postBody - httpBody The body of the HTTP request, which is also used to infer the
httpMethod.absoluteStreamPosition - The sum of uriPositionOffset and position.position - position.length - length.key - key.flags - flags.@Deprecated
public DataSpec(android.net.Uri uri,
@DataSpec.HttpMethod
int httpMethod,
byte[] httpBody,
long absoluteStreamPosition,
long position,
long length,
java.lang.String key,
@DataSpec.Flags
int flags)
DataSpec.Builder.uriPositionOffset may be non-zero.uri - uri.httpMethod - httpMethod.httpBody - httpBody.absoluteStreamPosition - The sum of uriPositionOffset and position.position - position.length - length.key - key.flags - flags.@Deprecated
public DataSpec(android.net.Uri uri,
@DataSpec.HttpMethod
int httpMethod,
byte[] httpBody,
long absoluteStreamPosition,
long position,
long length,
java.lang.String key,
@DataSpec.Flags
int flags,
java.util.Map<java.lang.String,java.lang.String> httpRequestHeaders)
DataSpec.Builder.uriPositionOffset may be non-zero.uri - uri.httpMethod - httpMethod.httpBody - httpBody.absoluteStreamPosition - The sum of uriPositionOffset and position.position - position.length - length.key - key.flags - flags.httpRequestHeaders - httpRequestHeaders.public static java.lang.String getStringForHttpMethod(@DataSpec.HttpMethod int httpMethod)
DataSpec.HttpMethod.public boolean isFlagSet(@DataSpec.Flags int flag)
flag - Flag to be checked if it is set.public final java.lang.String getHttpMethodString()
httpMethod.public DataSpec.Builder buildUpon()
DataSpec.Builder initialized with the values of this instance.public DataSpec subrange(long offset)
offset - The offset of the subrange.public DataSpec subrange(long offset, long length)
offset - The offset of the subrange.length - The length of the subrange.public DataSpec withUri(android.net.Uri uri)
uri - The new source Uri.public DataSpec withRequestHeaders(java.util.Map<java.lang.String,java.lang.String> httpRequestHeaders)
httpRequestHeaders - The HTTP request headers.public DataSpec withAdditionalHeaders(java.util.Map<java.lang.String,java.lang.String> additionalHttpRequestHeaders)
additionalHttpRequestHeaders will overwrite any headers already in the data spec that have the
same keys.additionalHttpRequestHeaders - The additional HTTP request headers.public java.lang.String toString()
toString 在类中 java.lang.Object