public class FileDownloadUrlConnection extends java.lang.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 java.net.URLConnection |
mConnection |
NO_RESPONSE_CODE, RESPONSE_CODE_FROM_OFFSET| Constructor and Description |
|---|
FileDownloadUrlConnection(java.lang.String originUrl) |
FileDownloadUrlConnection(java.lang.String originUrl,
FileDownloadUrlConnection.Configuration configuration) |
FileDownloadUrlConnection(java.net.URL url,
FileDownloadUrlConnection.Configuration configuration) |
| Modifier and Type | Method and Description |
|---|---|
void |
addHeader(java.lang.String name,
java.lang.String value)
Sets the header named
name to value. |
boolean |
dispatchAddResumeOffset(java.lang.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.
|
java.io.InputStream |
getInputStream()
Returns an input stream that reads from this open connection.
|
java.util.Map<java.lang.String,java.util.List<java.lang.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.
|
java.lang.String |
getResponseHeaderField(java.lang.String name)
Returns the value of the named header field, which would be the response-header field.
|
java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
getResponseHeaderFields()
Returns an unmodifiable Map of the header fields.
|
boolean |
setRequestMethod(java.lang.String method)
Set the method for the request, one of:
GET
POST
HEAD
OPTIONS
PUT
DELETE
TRACE
are legal, subject to protocol restrictions.
|
public FileDownloadUrlConnection(java.lang.String originUrl,
FileDownloadUrlConnection.Configuration configuration)
throws java.io.IOException
java.io.IOExceptionpublic FileDownloadUrlConnection(java.net.URL url,
FileDownloadUrlConnection.Configuration configuration)
throws java.io.IOException
java.io.IOExceptionpublic FileDownloadUrlConnection(java.lang.String originUrl)
throws java.io.IOException
java.io.IOExceptionpublic void addHeader(java.lang.String name,
java.lang.String value)
FileDownloadConnectionname to value.
The capacity of this method is similar to the
URLConnection.addRequestProperty(String, String)
addHeader in interface FileDownloadConnectionpublic boolean dispatchAddResumeOffset(java.lang.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 java.io.InputStream getInputStream()
throws java.io.IOException
FileDownloadConnection
The capacity of this method is similar to the URLConnection.getInputStream()
getInputStream in interface FileDownloadConnectionjava.io.IOExceptionpublic java.util.Map<java.lang.String,java.util.List<java.lang.String>> getRequestHeaderFields()
FileDownloadConnection
The capacity of this method is similar to the URLConnection.getRequestProperties()
getRequestHeaderFields in interface FileDownloadConnectionpublic java.util.Map<java.lang.String,java.util.List<java.lang.String>> getResponseHeaderFields()
FileDownloadConnection
The capacity of this method is similar to the URLConnection.getHeaderFields()
getResponseHeaderFields in interface FileDownloadConnectionpublic java.lang.String getResponseHeaderField(java.lang.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(java.lang.String method)
throws java.net.ProtocolException
FileDownloadConnectionsetRequestMethod in interface FileDownloadConnectionmethod - the HTTP methodtrue if set effect, otherwise false.java.net.ProtocolException - if the method cannot be reset or if
the requested method isn't valid for HTTP.public void execute()
throws java.io.IOException
FileDownloadConnectionexecute in interface FileDownloadConnectionjava.io.IOExceptionpublic int getResponseCode()
throws java.io.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 FileDownloadConnectionjava.io.IOExceptionpublic void ending()
FileDownloadConnectionending in interface FileDownloadConnection