目录

Class info
public final class BatchRequest
BatchRequest class.

Public Constructor Summary

Constructor name

BatchRequest(HttpTransport transport, HttpRequestInitializer httpRequestInitializer)

Constructor for the BatchRequest class.

Public Method Summary

Return typeMethod name
void

queue(BatchRequest batchRequest, JsonBatchCallbackcallback)

Queues the specified HTTP requests for batch processing.

void

execute()

Sends an HTTP request.

Public Constructors

constructor
public BatchRequest(HttpTransport transport, HttpRequestInitializer httpRequestInitializer)
Constructs an object of the BatchRequest class.
transportParameter nameParameter desc
transportHttpTransport object.
httpRequestInitializerHTTP request initializer.


Public Methods

Method
public final void queue(BatchRequest batchRequest, JsonBatchCallbackcallback) throws IOException
Queues the specified HTTP requests for batch processing. (This method is provided by the parent class and can be directly called.)

Parameters

Parameter nameParameter desc
batchRequestBatch request.
callbackBatch callback.


Throws

Parameter nameParameter desc
java.io.IOExceptionI/O exception thrown upon an API call failure. You can use the getMessage() method to obtain the error description.

Method
public void execute() throws IOException
Sends an HTTP request and returns the object to be converted.

Throws

Parameter nameParameter desc
java.io.IOExceptionI/O exception thrown upon an API call failure. You can use the getMessage() method to obtain the error description.

Sample Code

  1. JsonBatchCallback<File> callback = new JsonBatchCallback<File>() {
  2.      @Override
  3.      public void onFailure(JsonError e, HttpHeaders responseHeaders) throws IOException {
  4.           Log.i(TAG, "callback error: " + e.toString());
  5.      }
  6.      @Override
  7.      public void onSuccess(File file, HttpHeaders responseHeaders) throws IOException {
  8.           Log.i(TAG, "callback sucessful: " + e.toString());
  9.      }
  10. };
  11. // Create directories in batches.
  12. private void batchCreateDirectory(Drive drive, File file){
  13.      BatchRequest batch = drive.batch();
  14.      try{
  15.           for (int i = 0; i < 2; i++) {
  16.                Map<String, String> appProperties = new HashMap<>();
  17.                appProperties.put("appProperties", "property");
  18.                SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd_HHmmss_SSS");
  19.                String dirName = formatter.format(new Date()) + "_" + i;
  20.                Log.i(TAG, "executeFilesCreate: " + dirName);
  21.                File file = new File();
  22.                file.setFileName(dirName)
  23.                   .setAppSettings(appProperties)
  24.                   .setMimeType("application/vnd.huawei-apps.folder");
  25.                Drive.Files.Create create = drive.files().create(file);
  26.                create.queue(batch, callback);
  27.           }
  28.           batch.execute();
  29.        } catch (Exception e){
  30.           Log.e(TAG, "batchCreateDirectory error:" + e.toString());
  31.        }
  32. }