Package com.google.api.client.googleapis.media (2.1.0)

Media for Google API's.

Classes

MediaHttpDownloader

Media HTTP Downloader, with support for both direct and resumable media downloads. Documentation is available here.

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 with a new HttpBackOffUnsuccessfulResponseHandler instance and HttpRequest#setIOExceptionHandler 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.

MediaHttpUploader

Media HTTP Uploader, with support for both direct and resumable media uploads. Documentation is available here.

For resumable uploads, when the media content length is known, if the provided InputStream has InputStream#markSupported as false then it is wrapped in an BufferedInputStream to support the InputStream#mark and InputStream#reset methods required for handling server errors. If the media content length is unknown then each chunk is stored temporarily in memory. This is required to determine when the last chunk is reached.

See #setDisableGZipContent(boolean) for information on when content is gzipped and how to control that behavior.

Back-off is disabled by default. To enable it for an abnormal HTTP response and an I/O exception you should call HttpRequest#setUnsuccessfulResponseHandler with a new HttpBackOffUnsuccessfulResponseHandler instance and HttpRequest#setIOExceptionHandler with HttpBackOffIOExceptionHandler.

Upgrade warning: in prior version 1.14 exponential back-off was enabled by default for an abnormal HTTP response and there was a regular retry (without back-off) when I/O exception was thrown. Starting with version 1.15 back-off is disabled and there is no retry on I/O exception by default.

Upgrade warning: in prior version 1.16 #serverErrorCallback was public but starting with version 1.17 it has been removed from the public API, and changed to be package private.

Implementation is not thread-safe.

Interfaces

MediaHttpDownloaderProgressListener

An interface for receiving progress notifications for downloads.

Sample usage:


 public static class MyDownloadProgressListener implements MediaHttpDownloaderProgressListener {

   public void progressChanged(MediaHttpDownloader downloader) throws IOException {
     switch (downloader.getDownloadState()) {
       case MEDIA_IN_PROGRESS:
         System.out.println("Download in progress");
         System.out.println("Download percentage: " + downloader.getProgress());
         break;
       case MEDIA_COMPLETE:
         System.out.println("Download Completed!");
         break;
     }
   }
 }
 

MediaHttpUploaderProgressListener

An interface for receiving progress notifications for uploads.

Sample usage (if media content length is provided, else consider using MediaHttpUploader#getNumBytesUploaded instead of MediaHttpUploader#getProgress:


 public static class MyUploadProgressListener implements MediaHttpUploaderProgressListener {

   public void progressChanged(MediaHttpUploader uploader) throws IOException {
     switch (uploader.getUploadState()) {
       case INITIATION_STARTED:
         System.out.println("Initiation Started");
         break;
       case INITIATION_COMPLETE:
         System.out.println("Initiation Completed");
         break;
       case MEDIA_IN_PROGRESS:
         System.out.println("Upload in progress");
         System.out.println("Upload percentage: " + uploader.getProgress());
         break;
       case MEDIA_COMPLETE:
         System.out.println("Upload Completed!");
         break;
      }
   }
 }
 

Enums

MediaHttpDownloader.DownloadState

Download state associated with the Media HTTP downloader.

MediaHttpUploader.UploadState

Upload state associated with the Media HTTP uploader.