public interface HttpDataSource extends UriDataSource
UriDataSource
.Modifier and Type | Interface and Description |
---|---|
static class |
HttpDataSource.HttpDataSourceException
Thrown when an error is encountered when trying to read from a
HttpDataSource . |
static class |
HttpDataSource.InvalidContentTypeException
Thrown when the content type is invalid.
|
static class |
HttpDataSource.InvalidResponseCodeException
Thrown when an attempt to open a connection results in a response code not in the 2xx range.
|
Modifier and Type | Field and Description |
---|---|
static Predicate<String> |
REJECT_PAYWALL_TYPES
A
Predicate that rejects content types often used for pay-walls. |
Modifier and Type | Method and Description |
---|---|
void |
clearAllRequestProperties()
Clears all request header fields that were set by
setRequestProperty(String, String) . |
void |
clearRequestProperty(String name)
Clears the value of a request header field.
|
void |
close()
Closes the
DataSource . |
Map<String,List<String>> |
getResponseHeaders()
Gets the headers provided in the response.
|
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 . |
void |
setRequestProperty(String name,
String value)
Sets the value of a request header field.
|
getUri
long open(DataSpec dataSpec) throws HttpDataSource.HttpDataSourceException
DataSource
DataSource
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 DataSource
dataSpec
- 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
.HttpDataSource.HttpDataSourceException
void close() throws HttpDataSource.HttpDataSourceException
DataSource
DataSource
.
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 DataSource
HttpDataSource.HttpDataSourceException
int read(byte[] buffer, int offset, int readLength) throws HttpDataSource.HttpDataSourceException
DataSource
length
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 DataSource
buffer
- 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.HttpDataSource.HttpDataSourceException
void setRequestProperty(String name, String value)
name
- The name of the header field.value
- The value of the field.void clearRequestProperty(String name)
name
- The name of the header field.void clearAllRequestProperties()
setRequestProperty(String, String)
.