目录

Class info
public final class BatchRequest
BatchRequest类结构。

Public Constructor Summary

Constructor name

BatchRequest(HttpTransport transport, HttpRequestInitializer httpRequestInitializer)

BatchRequest类构造方法。

Public Method Summary

Return typeMethod name
void

queue(BatchRequest batchRequest, JsonBatchCallback<T> callback)

将指定的httpRequest进行排队等待批处理。

void

execute()

发送HTTP请求。

Public Constructors

constructor
public BatchRequest(HttpTransport transport, HttpRequestInitializer httpRequestInitializer)
构造一个BatchRequest对象。

Parameters

Parameter nameParameter desc
transportHttpTransport对象。
httpRequestInitializerhttp请求初始化。

Public Methods

Method
public final void queue(BatchRequest batchRequest, JsonBatchCallback<T> callback) throws IOException
将指定的httpRequest进行排队等待批处理(该方法是父类方法,可直接调用)。

Parameters

Parameter nameParameter desc
batchRequest批量请求。
callback批量回调。

Throws

Parameter nameParameter desc
java.io.IOException若接口调用异常,会返回IOException。开发者可以通过getMessage()方法获取错误描述。
Method
public void execute() throws IOException
发送HTTP请求,返回要转换的对象。

Throws

Parameter nameParameter desc
java.io.IOException若接口调用异常,会返回IOException。开发者可以通过getMessage()方法获取错误描述。

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. }