public class GSYDefaultHttpDataSource
extends BaseDataSource
HttpDataSource that uses Android's HttpURLConnection.
By default this implementation will not follow cross-protocol redirects (i.e. redirects from
HTTP to HTTPS or vice versa). Cross-protocol redirects can be enabled by using the GSYDefaultHttpDataSource(String, int, int, boolean, RequestProperties) constructor and passing
true for the allowCrossProtocolRedirects argument.
Note: HTTP request headers will be set using all parameters passed via (in order of decreasing
priority) the dataSpec, setRequestProperty(java.lang.String, java.lang.String) and the default parameters used to
construct the instance.
| 限定符和类型 | 字段和说明 |
|---|---|
static int |
DEFAULT_CONNECT_TIMEOUT_MILLIS
The default connection timeout, in milliseconds.
|
static int |
DEFAULT_READ_TIMEOUT_MILLIS
The default read timeout, in milliseconds.
|
| 构造器和说明 |
|---|
GSYDefaultHttpDataSource(java.lang.String userAgent) |
GSYDefaultHttpDataSource(java.lang.String userAgent,
<any> contentTypePredicate)
已过时。
Use
GSYDefaultHttpDataSource(String) and #setContentTypePredicate(Predicate). |
GSYDefaultHttpDataSource(java.lang.String userAgent,
<any> contentTypePredicate,
int connectTimeoutMillis,
int readTimeoutMillis)
已过时。
Use
GSYDefaultHttpDataSource(String, int, int) and #setContentTypePredicate(Predicate). |
GSYDefaultHttpDataSource(java.lang.String userAgent,
<any> contentTypePredicate,
int connectTimeoutMillis,
int readTimeoutMillis,
boolean allowCrossProtocolRedirects,
RequestProperties defaultRequestProperties)
已过时。
Use
GSYDefaultHttpDataSource(String, int, int, boolean, RequestProperties)
and #setContentTypePredicate(Predicate). |
GSYDefaultHttpDataSource(java.lang.String userAgent,
int connectTimeoutMillis,
int readTimeoutMillis) |
GSYDefaultHttpDataSource(java.lang.String userAgent,
int connectTimeoutMillis,
int readTimeoutMillis,
boolean allowCrossProtocolRedirects,
RequestProperties defaultRequestProperties) |
| 限定符和类型 | 方法和说明 |
|---|---|
protected long |
bytesRead()
Returns the number of bytes that have been read since the most recent call to
open(DataSpec). |
protected long |
bytesRemaining()
Returns the number of bytes that are still to be read for the current
DataSpec. |
protected long |
bytesSkipped()
Returns the number of bytes that have been skipped since the most recent call to
open(DataSpec). |
void |
clearAllRequestProperties() |
void |
clearRequestProperty(java.lang.String name) |
void |
close() |
protected java.net.HttpURLConnection |
getConnection()
Returns the current connection, or null if the source is not currently opened.
|
int |
getResponseCode() |
java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
getResponseHeaders() |
android.net.Uri |
getUri() |
long |
open(DataSpec dataSpec)
Opens the source to read the specified data.
|
int |
read(byte[] buffer,
int offset,
int readLength) |
void |
setContentTypePredicate(<any> contentTypePredicate)
Sets a content type
Predicate. |
void |
setRequestProperty(java.lang.String name,
java.lang.String value) |
public static final int DEFAULT_CONNECT_TIMEOUT_MILLIS
public static final int DEFAULT_READ_TIMEOUT_MILLIS
public GSYDefaultHttpDataSource(java.lang.String userAgent)
userAgent - The User-Agent string that should be used.public GSYDefaultHttpDataSource(java.lang.String userAgent,
int connectTimeoutMillis,
int readTimeoutMillis)
userAgent - The User-Agent string that should be used.connectTimeoutMillis - The connection timeout, in milliseconds. A timeout of zero is
interpreted as an infinite timeout.readTimeoutMillis - The read timeout, in milliseconds. A timeout of zero is interpreted as
an infinite timeout.public GSYDefaultHttpDataSource(java.lang.String userAgent,
int connectTimeoutMillis,
int readTimeoutMillis,
boolean allowCrossProtocolRedirects,
RequestProperties defaultRequestProperties)
userAgent - The User-Agent string that should be used.connectTimeoutMillis - The connection timeout, in milliseconds. A timeout of zero is
interpreted as an infinite timeout. Pass DEFAULT_CONNECT_TIMEOUT_MILLIS to use the
default value.readTimeoutMillis - The read timeout, in milliseconds. A timeout of zero is interpreted as
an infinite timeout. Pass DEFAULT_READ_TIMEOUT_MILLIS to use the default value.allowCrossProtocolRedirects - Whether cross-protocol redirects (i.e. redirects from HTTP
to HTTPS and vice versa) are enabled.defaultRequestProperties - The default request properties to be sent to the server as HTTP
headers or null if not required.@Deprecated
public GSYDefaultHttpDataSource(java.lang.String userAgent,
<any> contentTypePredicate)
GSYDefaultHttpDataSource(String) and #setContentTypePredicate(Predicate).userAgent - The User-Agent string that should be used.contentTypePredicate - An optional Predicate. If a content type is rejected by the
predicate then a HttpDataSource.InvalidContentTypeException is thrown from open(DataSpec).@Deprecated
public GSYDefaultHttpDataSource(java.lang.String userAgent,
<any> contentTypePredicate,
int connectTimeoutMillis,
int readTimeoutMillis)
GSYDefaultHttpDataSource(String, int, int) and #setContentTypePredicate(Predicate).userAgent - The User-Agent string that should be used.contentTypePredicate - An optional Predicate. If a content type is rejected by the
predicate then a HttpDataSource.InvalidContentTypeException is thrown from open(DataSpec).connectTimeoutMillis - The connection timeout, in milliseconds. A timeout of zero is
interpreted as an infinite timeout.readTimeoutMillis - The read timeout, in milliseconds. A timeout of zero is interpreted as
an infinite timeout.@Deprecated
public GSYDefaultHttpDataSource(java.lang.String userAgent,
<any> contentTypePredicate,
int connectTimeoutMillis,
int readTimeoutMillis,
boolean allowCrossProtocolRedirects,
RequestProperties defaultRequestProperties)
GSYDefaultHttpDataSource(String, int, int, boolean, RequestProperties)
and #setContentTypePredicate(Predicate).userAgent - The User-Agent string that should be used.contentTypePredicate - An optional Predicate. If a content type is rejected by the
predicate then a HttpDataSource.InvalidContentTypeException is thrown from open(DataSpec).connectTimeoutMillis - The connection timeout, in milliseconds. A timeout of zero is
interpreted as an infinite timeout. Pass DEFAULT_CONNECT_TIMEOUT_MILLIS to use the
default value.readTimeoutMillis - The read timeout, in milliseconds. A timeout of zero is interpreted as
an infinite timeout. Pass DEFAULT_READ_TIMEOUT_MILLIS to use the default value.allowCrossProtocolRedirects - Whether cross-protocol redirects (i.e. redirects from HTTP
to HTTPS and vice versa) are enabled.defaultRequestProperties - The default request properties to be sent to the server as HTTP
headers or null if not required.public void setContentTypePredicate(<any> contentTypePredicate)
Predicate. If a content type is rejected by the predicate then a
HttpDataSource.InvalidContentTypeException is thrown from open(DataSpec).contentTypePredicate - The content type Predicate, or null to clear a
predicate that was previously set.public android.net.Uri getUri()
public int getResponseCode()
public java.util.Map<java.lang.String,java.util.List<java.lang.String>> getResponseHeaders()
public void setRequestProperty(java.lang.String name,
java.lang.String value)
public void clearRequestProperty(java.lang.String name)
public void clearAllRequestProperties()
public long open(DataSpec dataSpec)
throws HttpDataSourceException
HttpDataSourceExceptionpublic int read(byte[] buffer,
int offset,
int readLength)
throws HttpDataSourceException
HttpDataSourceExceptionpublic void close()
throws HttpDataSourceException
HttpDataSourceExceptionprotected final java.net.HttpURLConnection getConnection()
protected final long bytesSkipped()
open(DataSpec).protected final long bytesRead()
open(DataSpec).protected final long bytesRemaining()
DataSpec.
If the total length of the data being read is known, then this length minus bytesRead()
is returned. If the total length is unknown, C#LENGTH_UNSET is returned.
C#LENGTH_UNSET.