Skip to content

Commit 4730168

Browse files
committed
new BucketManager.Batch()
1 parent 513a8a5 commit 4730168

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/main/java/com/qiniu/storage/BucketManager.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,10 @@ private Response post(String url, byte[] body) throws QiniuException {
137137
return client.post(url, body, headers, Client.FormMime);
138138
}
139139

140-
public static Batch createBatch() {
141-
return new Batch();
142-
}
143-
144140
public static class Batch {
145141
private ArrayList<String> ops;
146142

147-
private Batch() {
143+
public Batch() {
148144
this.ops = new ArrayList<String>();
149145
}
150146

@@ -184,6 +180,11 @@ public byte[] toBody() {
184180
String body = StringUtils.join(ops, "&op=", "op=");
185181
return StringUtils.utf8Bytes(body);
186182
}
183+
184+
public Batch merge(Batch batch) {
185+
this.ops.addAll(batch.ops);
186+
return this;
187+
}
187188
}
188189

189190
public class FileListIterator implements Iterator<FileInfo[]> {

src/test/java/com/qiniu/storage/BucketTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public void testFetch() {
158158
@Test
159159
public void testBatchCopy() {
160160
String key = "copyTo" + Math.random();
161-
BucketManager.Batch ops = BucketManager.createBatch().
161+
BucketManager.Batch ops = new BucketManager.Batch().
162162
copy(TestConfig.bucket, TestConfig.key, TestConfig.bucket, key);
163163
try {
164164
Response r = bucketManager.batch(ops);
@@ -168,7 +168,7 @@ public void testBatchCopy() {
168168
e.printStackTrace();
169169
fail();
170170
}
171-
ops = BucketManager.createBatch().delete(TestConfig.bucket, key);
171+
ops = new BucketManager.Batch().delete(TestConfig.bucket, key);
172172
try {
173173
Response r = bucketManager.batch(ops);
174174
BatchStatus[] bs = r.jsonToObject(BatchStatus[].class);
@@ -189,7 +189,7 @@ public void testBatchMove() {
189189
}
190190
String key2 = key + "to";
191191
StringMap x = new StringMap().put(key, key2);
192-
BucketManager.Batch ops = BucketManager.createBatch().move(TestConfig.bucket,
192+
BucketManager.Batch ops = new BucketManager.Batch().move(TestConfig.bucket,
193193
key, TestConfig.bucket, key2);
194194
try {
195195
Response r = bucketManager.batch(ops);
@@ -217,7 +217,7 @@ public void testBatchRename() {
217217
fail();
218218
}
219219
String key2 = key + "to";
220-
BucketManager.Batch ops = BucketManager.createBatch().rename(TestConfig.bucket, key, key2);
220+
BucketManager.Batch ops = new BucketManager.Batch().rename(TestConfig.bucket, key, key2);
221221
try {
222222
Response r = bucketManager.batch(ops);
223223
BatchStatus[] bs = r.jsonToObject(BatchStatus[].class);
@@ -237,7 +237,7 @@ public void testBatchRename() {
237237
@Test
238238
public void testBatchStat() {
239239
String[] array = {"java-sdk.html"};
240-
BucketManager.Batch ops = BucketManager.createBatch().stat(TestConfig.bucket, array);
240+
BucketManager.Batch ops = new BucketManager.Batch().stat(TestConfig.bucket, array);
241241
try {
242242
Response r = bucketManager.batch(ops);
243243
BatchStatus[] bs = r.jsonToObject(BatchStatus[].class);
@@ -267,7 +267,7 @@ public void testBatch() {
267267
fail();
268268
}
269269

270-
BucketManager.Batch ops = BucketManager.createBatch()
270+
BucketManager.Batch ops = new BucketManager.Batch()
271271
.copy(TestConfig.bucket, TestConfig.key, TestConfig.bucket, key)
272272
.move(TestConfig.bucket, key1, TestConfig.bucket, key2)
273273
.rename(TestConfig.bucket, key3, key4)

0 commit comments

Comments
 (0)