public class FileDownloadUrlConnection extends Object implements FileDownloadConnection
URLConnection.| Modifier and Type | Class and Description |
|---|---|
static class |
FileDownloadUrlConnection.Configuration
The sample configuration for the
FileDownloadUrlConnection |
static class |
FileDownloadUrlConnection.Creator |
| Modifier and Type | Field and Description |
|---|---|
protected URLConnection |
mConnection |
NO_RESPONSE_CODE, RESPONSE_CODE_FROM_OFFSET| Constructor and Description |
|---|
FileDownloadUrlConnection(String originUrl) |
FileDownloadUrlConnection(String originUrl,
FileDownloadUrlConnection.Configuration configuration) |
FileDownloadUrlConnection(URL url,
FileDownloadUrlConnection.Configuration configuration) |
| Modifier and Type | Method and Description |
|---|---|
void |
addHeader(String name,
String value)
Sets the header named
name to value. |
boolean |
dispatchAddResumeOffset(String etag,
long offset)
If we find the file has been downloaded several bytes, we will try to resume from the
breakpoint from
offset length. |
void |
ending()
To Be Reused or Close this connection, since this connection is ending in this session.
|
void |
execute()
Invokes the request immediately, and blocks until the response can be processed or is in
error.
|
InputStream |
getInputStream()
Returns an input stream that reads from this open connection.
|
Map<String,List<String>> |
getRequestHeaderFields()
Returns an unmodifiable Map of general request header fields for this connection.
|
int |
getResponseCode()
Gets the status code from an HTTP response message.
|
String |
getResponseHeaderField(String name)
Returns the value of the named header field, which would be the response-header field.
|
Map<String,List<String>> |
getResponseHeaderFields()
Returns an unmodifiable Map of the header fields.
|
boolean |
setRequestMethod(String method)
Set the method for the request, one of:
GET
POST
HEAD
OPTIONS
PUT
DELETE
TRACE
are legal, subject to protocol restrictions.
|
protected URLConnection mConnection
public FileDownloadUrlConnection(String originUrl, FileDownloadUrlConnection.Configuration configuration) throws IOException
IOExceptionpublic FileDownloadUrlConnection(URL url, FileDownloadUrlConnection.Configuration configuration) throws IOException
IOExceptionpublic FileDownloadUrlConnection(String originUrl) throws IOException
IOExceptionpublic void addHeader(String name, String value)
FileDownloadConnectionname to value.
The capacity of this method is similar to the
URLConnection.addRequestProperty(String, String)
addHeader in interface FileDownloadConnectionpublic boolean dispatchAddResumeOffset(String etag, long offset)
FileDownloadConnectionoffset length.dispatchAddResumeOffset in interface FileDownloadConnectionetag - the etag is stored by the past downloaded.offset - the offset length has already been downloaded.true if adding resume offset was dispatched, so we can't handle that by
internal.public InputStream getInputStream() throws IOException
FileDownloadConnection
The capacity of this method is similar to the URLConnection.getInputStream()
getInputStream in interface FileDownloadConnectionIOExceptionpublic Map<String,List<String>> getRequestHeaderFields()
FileDownloadConnection
The capacity of this method is similar to the URLConnection.getRequestProperties()
getRequestHeaderFields in interface FileDownloadConnectionpublic Map<String,List<String>> getResponseHeaderFields()
FileDownloadConnection
The capacity of this method is similar to the URLConnection.getHeaderFields()
getResponseHeaderFields in interface FileDownloadConnectionpublic String getResponseHeaderField(String name)
FileDownloadConnectionIf called on a connection that sets the same header multiple times with possibly different values, only the last value is returned.
getResponseHeaderField in interface FileDownloadConnectionname - the name of a header field.null
if there is no such field in the header.public boolean setRequestMethod(String method) throws ProtocolException
FileDownloadConnectionsetRequestMethod in interface FileDownloadConnectionmethod - the HTTP methodtrue if set effect, otherwise false.ProtocolException - if the method cannot be reset or if
the requested method isn't valid for HTTP.public void execute()
throws IOException
FileDownloadConnectionexecute in interface FileDownloadConnectionIOExceptionpublic int getResponseCode()
throws IOException
FileDownloadConnection
If this is not http/https protocol connection:
1. If you make sure this connection is resume from the offset breakpoint(which you can check
out this through FileDownloadConnection.dispatchAddResumeOffset(String, long)), please return
FileDownloadConnection.RESPONSE_CODE_FROM_OFFSET
2. otherwise, return FileDownloadConnection.NO_RESPONSE_CODE.
getResponseCode in interface FileDownloadConnectionIOExceptionpublic void ending()
FileDownloadConnectionending in interface FileDownloadConnection