public final class MediaHttpDownloader extends Object
Implementation is not thread-safe.
Back-off is disabled by default. To enable it for an abnormal HTTP response and an I/O exception
you should call HttpRequest.setUnsuccessfulResponseHandler(com.google.api.client.http.HttpUnsuccessfulResponseHandler)
with a new
HttpBackOffUnsuccessfulResponseHandler
instance and
HttpRequest.setIOExceptionHandler(com.google.api.client.http.HttpIOExceptionHandler)
with HttpBackOffIOExceptionHandler
.
Upgrade warning: in prior version 1.14 exponential back-off was enabled by default for an abnormal HTTP response. Starting with version 1.15 it's disabled by default.
Modifier and Type | Class and Description |
---|---|
static class |
MediaHttpDownloader.DownloadState
Download state associated with the Media HTTP downloader.
|
Modifier and Type | Field and Description |
---|---|
static int |
MAXIMUM_CHUNK_SIZE
Default maximum number of bytes that will be downloaded from the server in any single HTTP
request.
|
Constructor and Description |
---|
MediaHttpDownloader(HttpTransport transport,
HttpRequestInitializer httpRequestInitializer)
Construct the
MediaHttpDownloader . |
Modifier and Type | Method and Description |
---|---|
void |
download(GenericUrl requestUrl,
HttpHeaders requestHeaders,
OutputStream outputStream)
Executes a direct media download or a resumable media download.
|
void |
download(GenericUrl requestUrl,
OutputStream outputStream)
Executes a direct media download or a resumable media download.
|
int |
getChunkSize()
Returns the maximum size of individual chunks that will get downloaded by single HTTP requests.
|
MediaHttpDownloader.DownloadState |
getDownloadState()
Gets the current download state of the downloader.
|
long |
getLastBytePosition()
Gets the last byte position of the media file we want to download or
-1 if there is no
upper limit on the byte position. |
long |
getNumBytesDownloaded()
Gets the total number of bytes downloaded by this downloader.
|
double |
getProgress()
Gets the download progress denoting the percentage of bytes that have been downloaded,
represented between 0.0 (0%) and 1.0 (100%).
|
MediaHttpDownloaderProgressListener |
getProgressListener()
Returns the progress listener to send progress notifications to or
null for none. |
HttpTransport |
getTransport()
Returns the transport to use for requests.
|
boolean |
isDirectDownloadEnabled()
Returns whether direct media download is enabled or disabled.
|
MediaHttpDownloader |
setBytesDownloaded(long bytesDownloaded)
Sets the total number of bytes that have been downloaded of the media resource.
|
MediaHttpDownloader |
setChunkSize(int chunkSize)
Sets the maximum size of individual chunks that will get downloaded by single HTTP requests.
|
MediaHttpDownloader |
setContentRange(long firstBytePos,
int lastBytePos)
Deprecated.
Use
setContentRange(long, long) instead. |
MediaHttpDownloader |
setContentRange(long firstBytePos,
long lastBytePos)
Sets the content range of the next download request.
|
MediaHttpDownloader |
setDirectDownloadEnabled(boolean directDownloadEnabled)
Returns whether direct media download is enabled or disabled.
|
MediaHttpDownloader |
setProgressListener(MediaHttpDownloaderProgressListener progressListener)
Sets the progress listener to send progress notifications to or
null for none. |
public static final int MAXIMUM_CHUNK_SIZE
public MediaHttpDownloader(HttpTransport transport, HttpRequestInitializer httpRequestInitializer)
MediaHttpDownloader
.transport
- The transport to use for requestshttpRequestInitializer
- The initializer to use when creating an HttpRequest
or
null
for nonepublic void download(GenericUrl requestUrl, OutputStream outputStream) throws IOException
This method does not close the given output stream.
This method is not reentrant. A new instance of MediaHttpDownloader
must be
instantiated before download called be called again.
requestUrl
- The request URL where the download requests will be sentoutputStream
- destination output streamIOException
public void download(GenericUrl requestUrl, HttpHeaders requestHeaders, OutputStream outputStream) throws IOException
This method does not close the given output stream.
This method is not reentrant. A new instance of MediaHttpDownloader
must be
instantiated before download called be called again.
requestUrl
- request URL where the download requests will be sentrequestHeaders
- request headers or null
to ignoreoutputStream
- destination output streamIOException
public MediaHttpDownloader setBytesDownloaded(long bytesDownloaded)
If a download was aborted mid-way due to a connection failure then users can resume the download from the point where it left off.
Use setContentRange(long, long)
if you need to specify both the bytes downloaded and the last byte
position.
bytesDownloaded
- The total number of bytes downloadedpublic MediaHttpDownloader setContentRange(long firstBytePos, long lastBytePos)
If a download was aborted mid-way due to a connection failure then users can resume the download from the point where it left off.
Use setBytesDownloaded(long)
if you only need to specify the first byte position.
firstBytePos
- The first byte position in the content range stringlastBytePos
- The last byte position in the content range string.@Deprecated public MediaHttpDownloader setContentRange(long firstBytePos, int lastBytePos)
setContentRange(long, long)
instead.public boolean isDirectDownloadEnabled()
true
then a direct download will be done where the whole media content is downloaded in a single
request. If value is set to false
then the download uses the resumable media download
protocol to download in data chunks. Defaults to false
.public MediaHttpDownloader setDirectDownloadEnabled(boolean directDownloadEnabled)
true
then a direct download will be done where the whole media content is downloaded in a single
request. If value is set to false
then the download uses the resumable media download
protocol to download in data chunks. Defaults to false
.public MediaHttpDownloader setProgressListener(MediaHttpDownloaderProgressListener progressListener)
null
for none.public MediaHttpDownloaderProgressListener getProgressListener()
null
for none.public HttpTransport getTransport()
public MediaHttpDownloader setChunkSize(int chunkSize)
MAXIMUM_CHUNK_SIZE
.
The maximum allowable value is MAXIMUM_CHUNK_SIZE
.
public int getChunkSize()
MAXIMUM_CHUNK_SIZE
.public long getNumBytesDownloaded()
public long getLastBytePosition()
-1
if there is no
upper limit on the byte position.public MediaHttpDownloader.DownloadState getDownloadState()
public double getProgress()
Copyright © 2010–2020 Google. All rights reserved.