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