| Class info |
| public final class BatchRequest |
| BatchRequest class. |
| Constructor name |
BatchRequest(HttpTransport transport, HttpRequestInitializer httpRequestInitializer) Constructor for the BatchRequest class. |
| Return type | Method name |
| void | queue(BatchRequest batchRequest, JsonBatchCallbackcallback) Queues the specified HTTP requests for batch processing. |
| void | execute() Sends an HTTP request. |
| constructor |
| public BatchRequest(HttpTransport transport, HttpRequestInitializer httpRequestInitializer) |
| Constructs an object of the BatchRequest class. |
| transportParameter name | Parameter desc |
| transport | HttpTransport object. |
| httpRequestInitializer | HTTP request initializer. |
| 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 name | Parameter desc |
| batchRequest | Batch request. |
| callback | Batch callback. |
Throws
| Parameter name | Parameter desc |
| java.io.IOException | I/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 name | Parameter desc |
| 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 sucessful: " + e.toString());
- }
- };
- // Create directories in batches.
- 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());
- }
- }