目录

BatchRequest

Class Info

public final class BatchRequest

BatchRequest class.

Public Constructor Summary

Constructor Name

BatchRequest(HttpTransport transport, HttpRequestInitializer httpRequestInitializer )

Constructs a BatchRequest object.

Public Method Summary

Qualifier and Type

Method Name and Description

void

execute()

Sends an HTTP request.

void

queue(HttpRequest httpRequest, Class<T> dataClass, Class<E> errorClass, BatchCallback<T, E> callback)

Queues the specified HTTP requests for batch processing.

Public Constructors

[h2]BatchRequest

Constructor

public BatchRequest(HttpTransport transport, HttpRequestInitializer httpRequestInitializer)

Constructs a BatchRequest object.

Parameters

Name

Description

transport

HttpTransport object.

httpRequestInitializer

HTTP request initializer.

Public Methods

[h2]queue

Method

public final void queue(HttpRequest httpRequest, Class<T> dataClass, Class<E> errorClass, BatchCallback<T, E> callback) throws IOException

Queues the specified HTTP requests for batch processing. (This method is provided by the parent class and can be directly called.)

Parameters

Name

Description

httpRequest

Batch request.

dataClass

Response parsing.

errorClass

Error response parsing.

callback

Batch callback.

Throws

Name

Description

java.io.IOException

I/O exception thrown upon an API call failure. You can use the getMessage() method to obtain the error description.

[h2]execute

Method

public void execute() throws IOException

Sends an HTTP request and returns the object to be converted.

Throws

Name

Description

java.io.IOException

I/O exception thrown upon an API call failure. You can use the getMessage() method to obtain the error description.

Sample Code

JsonBatchCallback<File> callback = new JsonBatchCallback<File>() {
    @Override
    public void onFailure(JsonError e, HttpHeaders responseHeaders) throws IOException {
        Log.i(TAG, "callback error: " + e.toString());
    }
    @Override
    public void onSuccess(File file, HttpHeaders responseHeaders) throws IOException {
        Log.i(TAG, "callback successful: " + e.toString());
    }
};
// Create a batch of directories. 
private void batchCreateDirectory(Drive drive, File file){
    BatchRequest batch = drive.batch();
    try{
        for (int i = 0; i < 2; i++) {
            Map<String, String> appProperties = new HashMap<>();
            appProperties.put("appProperties", "property");
            SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd_HHmmss_SSS");
            String dirName = formatter.format(new Date()) + "_" + i;
            Log.i(TAG, "executeFilesCreate: " + dirName);
            File file = new File();
            file.setFileName(dirName)
            .setAppSettings(appProperties)
            .setMimeType("application/vnd.huawei-apps.folder");
            Drive.Files.Create create = drive.files().create(file);
            create.queue(batch, callback);
        }
        batch.execute();
        } catch (Exception e){
            Log.e(TAG, "batchCreateDirectory error:" + e.toString());
    }
}