| Class info |
| public final class BatchRequest |
| BatchRequest类结构。 |
| Constructor name |
BatchRequest(HttpTransport transport, HttpRequestInitializer httpRequestInitializer) BatchRequest类构造方法。 |
| Return type | Method name |
| void | queue(BatchRequest batchRequest, JsonBatchCallback<T> callback) 将指定的httpRequest进行排队等待批处理。 |
| void | execute() 发送HTTP请求。 |
| constructor |
| public BatchRequest(HttpTransport transport, HttpRequestInitializer httpRequestInitializer) |
| 构造一个BatchRequest对象。 |
Parameters
| Parameter name | Parameter desc |
| transport | HttpTransport对象。 |
| httpRequestInitializer | http请求初始化。 |
| Method |
| public final void queue(BatchRequest batchRequest, JsonBatchCallback<T> callback) throws IOException |
| 将指定的httpRequest进行排队等待批处理(该方法是父类方法,可直接调用)。 |
Parameters
| Parameter name | Parameter desc |
| batchRequest | 批量请求。 |
| callback | 批量回调。 |
Throws
| Parameter name | Parameter desc |
| java.io.IOException | 若接口调用异常,会返回IOException。开发者可以通过getMessage()方法获取错误描述。 |
| Method |
| public void execute() throws IOException |
| 发送HTTP请求,返回要转换的对象。 |
Throws
| Parameter name | Parameter desc |
| java.io.IOException | 若接口调用异常,会返回IOException。开发者可以通过getMessage()方法获取错误描述。 |
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());
- }
- }