Skip to content

Commit 50542ad

Browse files
author
Joshua Yin
committed
* ObjectProfileApi新增CreateTime字段
* 所有Object的API均添加response headers Map<String,String> * ObjectProfileSample新增批量调用demo
1 parent 5203108 commit 50542ad

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+557
-162
lines changed

ufile-sample-java/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<dependency>
2727
<groupId>cn.ucloud.ufile</groupId>
2828
<artifactId>ufile-client-java</artifactId>
29-
<version>2.4.0</version>
29+
<version>2.4.1</version>
3030
</dependency>
3131
</dependencies>
3232

ufile-sample-java/src/main/java/cn/ucloud/ufile/sample/object/AppendObjectSample.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
import cn.ucloud.ufile.http.UfileCallback;
1212
import cn.ucloud.ufile.sample.Constants;
1313
import cn.ucloud.ufile.util.JLog;
14+
import cn.ucloud.ufile.util.MimeTypeUtil;
1415
import okhttp3.Request;
1516

16-
1717
/**
1818
* @author: joshua
1919
* @E-mail: [email protected]
@@ -25,8 +25,8 @@ public class AppendObjectSample {
2525

2626
public static void main(String[] args) {
2727
byte[] appendData = new byte[]{0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00};
28-
String mimeType = "";
2928
String keyName = "";
29+
String mimeType = MimeTypeUtil.getMimeType(keyName);
3030
String bucketName = "";
3131
long posistion = 0;
3232
appendObject(appendData, mimeType, bucketName, keyName, posistion);
@@ -59,7 +59,7 @@ public void onProgress(long bytesWritten, long contentLength) {
5959
}
6060
})
6161
.execute();
62-
JLog.D(TAG, String.format("[res] = %s", (response == null ? "null" : response.toString())));
62+
JLog.D(TAG, String.format("[res]: %s", (response == null ? "null" : response.toString())));
6363
} catch (UfileClientException e) {
6464
e.printStackTrace();
6565
} catch (UfileServerException e) {

ufile-sample-java/src/main/java/cn/ucloud/ufile/sample/object/DeleteObjectSample.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import cn.ucloud.ufile.UfileClient;
44
import cn.ucloud.ufile.api.ApiError;
55
import cn.ucloud.ufile.api.object.ObjectConfig;
6-
import cn.ucloud.ufile.bean.base.BaseResponseBean;
6+
import cn.ucloud.ufile.bean.base.BaseObjectResponseBean;
77
import cn.ucloud.ufile.bean.UfileErrorBean;
88
import cn.ucloud.ufile.exception.UfileClientException;
99
import cn.ucloud.ufile.exception.UfileServerException;
@@ -30,7 +30,7 @@ public static void main(String[] args) {
3030

3131
public static void execute(String keyName, String bucketName) {
3232
try {
33-
BaseResponseBean response = UfileClient.object(Constants.OBJECT_AUTHORIZER, config)
33+
BaseObjectResponseBean response = UfileClient.object(Constants.OBJECT_AUTHORIZER, config)
3434
.deleteObject(keyName, bucketName)
3535
.execute();
3636
JLog.D(TAG, String.format("[res] = %s", (response == null ? "null" : response.toString())));
@@ -44,10 +44,10 @@ public static void execute(String keyName, String bucketName) {
4444
public static void executeAsync(String keyName, String bucketName) {
4545
UfileClient.object(Constants.OBJECT_AUTHORIZER, config)
4646
.deleteObject(keyName, bucketName)
47-
.executeAsync(new UfileCallback<BaseResponseBean>() {
47+
.executeAsync(new UfileCallback<BaseObjectResponseBean>() {
4848

4949
@Override
50-
public void onResponse(BaseResponseBean response) {
50+
public void onResponse(BaseObjectResponseBean response) {
5151
JLog.D(TAG, String.format("[res] = %s", (response == null ? "null" : response.toString())));
5252
}
5353

ufile-sample-java/src/main/java/cn/ucloud/ufile/sample/object/ObjectProfileSample.java

Lines changed: 106 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
import cn.ucloud.ufile.util.JLog;
1313
import okhttp3.Request;
1414

15+
import java.util.ArrayList;
16+
import java.util.List;
17+
import java.util.Map;
18+
import java.util.concurrent.*;
19+
1520
/**
1621
* @author: joshua
1722
* @E-mail: [email protected]
@@ -25,15 +30,108 @@ public static void main(String[] args) {
2530
String keyName = "";
2631
String bucketName = "";
2732

28-
execute(keyName, bucketName);
33+
// execute(keyName, bucketName);
34+
List<Info> infos = new ArrayList<>();
35+
infos.add(new Info(bucketName).setKeyName(""));
36+
infos.add(new Info(bucketName).setKeyName(""));
37+
infos.add(new Info(bucketName).setKeyName(""));
38+
infos.add(new Info(bucketName).setKeyName(""));
39+
infos.add(new Info(bucketName).setKeyName(""));
40+
batch(infos);
41+
}
42+
43+
private static class Info {
44+
private String bucket;
45+
private String keyName;
46+
47+
public Info(String bucket) {
48+
this.bucket = bucket;
49+
}
50+
51+
public String getBucket() {
52+
return bucket;
53+
}
54+
55+
public Info setBucket(String bucket) {
56+
this.bucket = bucket;
57+
return this;
58+
}
59+
60+
public String getKeyName() {
61+
return keyName;
62+
}
63+
64+
public Info setKeyName(String keyName) {
65+
this.keyName = keyName;
66+
return this;
67+
}
68+
}
69+
70+
public static void batch(List<Info> infos) {
71+
if (infos == null || infos.isEmpty())
72+
return;
73+
74+
ExecutorService threadPool = new ThreadPoolExecutor(5, 10,
75+
0L, TimeUnit.MILLISECONDS,
76+
new LinkedBlockingQueue<Runnable>());
77+
78+
List<ObjectProfileCallable> callables = new ArrayList<>();
79+
for (Info info : infos) {
80+
callables.add(new ObjectProfileCallable(info));
81+
}
82+
83+
try {
84+
List<Future<ObjectProfile>> futures = threadPool.invokeAll(callables);
85+
for (Future<ObjectProfile> future : futures) {
86+
try {
87+
JLog.D(TAG, "=====================================================================\n");
88+
ObjectProfile objectProfile = future.get();
89+
JLog.D(TAG, String.format("[res]: %s", (objectProfile == null ? "null" : objectProfile.toString())));
90+
Map<String, String> headers = objectProfile.getHeaders();
91+
if (headers != null) {
92+
for (Map.Entry<String, String> entry : headers.entrySet()) {
93+
JLog.D(TAG, "\t\t[key]:" + entry.getKey() + "\t[val]:" + entry.getValue());
94+
}
95+
}
96+
} catch (ExecutionException e) {
97+
JLog.D(TAG, String.format("[err]: %s", e.getMessage()));
98+
}
99+
}
100+
} catch (InterruptedException e) {
101+
e.printStackTrace();
102+
} finally {
103+
threadPool.shutdownNow();
104+
}
105+
}
106+
107+
private static class ObjectProfileCallable implements Callable<ObjectProfile> {
108+
private Info info;
109+
110+
public ObjectProfileCallable(Info info) {
111+
this.info = info;
112+
}
113+
114+
@Override
115+
public ObjectProfile call() throws Exception {
116+
Thread.sleep(5000);
117+
return UfileClient.object(Constants.OBJECT_AUTHORIZER, config)
118+
.objectProfile(info.getKeyName(), info.getBucket())
119+
.execute();
120+
}
29121
}
30122

31123
public static void execute(String keyName, String bucketName) {
32124
try {
33125
ObjectProfile objectProfile = UfileClient.object(Constants.OBJECT_AUTHORIZER, config)
34126
.objectProfile(keyName, bucketName)
35127
.execute();
36-
JLog.D(TAG, String.format("[res] = %s", (objectProfile == null ? "null" : objectProfile.toString())));
128+
JLog.D(TAG, String.format("[res]: %s", (objectProfile == null ? "null" : objectProfile.toString())));
129+
Map<String, String> headers = objectProfile.getHeaders();
130+
if (headers != null) {
131+
for (Map.Entry<String, String> entry : headers.entrySet()) {
132+
JLog.D(TAG, "[key]:" + entry.getKey() + " [val]:" + entry.getValue());
133+
}
134+
}
37135
} catch (UfileClientException e) {
38136
e.printStackTrace();
39137
} catch (UfileServerException e) {
@@ -49,6 +147,12 @@ public static void executeAsync(String keyName, String bucketName) {
49147
@Override
50148
public void onResponse(ObjectProfile response) {
51149
JLog.D(TAG, String.format("[res] = %s", (response == null ? "null" : response.toString())));
150+
Map<String, String> headers = response.getHeaders();
151+
if (headers != null) {
152+
for (Map.Entry<String, String> entry : headers.entrySet()) {
153+
JLog.D(TAG, "[key]:" + entry.getKey() + " [val]:" + entry.getValue());
154+
}
155+
}
52156
}
53157

54158
@Override

ufile-sample-java/src/main/java/cn/ucloud/ufile/sample/object/ObjectRestoreSample.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
import cn.ucloud.ufile.UfileClient;
44
import cn.ucloud.ufile.api.object.ObjectConfig;
5-
import cn.ucloud.ufile.bean.base.BaseResponseBean;
5+
import cn.ucloud.ufile.bean.base.BaseObjectResponseBean;
66
import cn.ucloud.ufile.sample.Constants;
7+
import cn.ucloud.ufile.util.JLog;
78

89
/**
910
* @author: joshua
@@ -12,16 +13,16 @@
1213
*/
1314
public class ObjectRestoreSample {
1415
private static final String TAG = "ObjectRestoreSample";
15-
private static ObjectConfig config = new ObjectConfig("cn-gd", "ufileos.com");
16+
private static ObjectConfig config = new ObjectConfig("cn-sh2", "ufileos.com");
1617

1718
public static void main(String[] args) {
18-
String keyName = "a.jpg";
19-
String bucketName = "ufile-test-gd";
19+
String keyName = "";
20+
String bucketName = "";
2021
try {
21-
BaseResponseBean a = UfileClient.object(Constants.OBJECT_AUTHORIZER, config)
22+
BaseObjectResponseBean response = UfileClient.object(Constants.OBJECT_AUTHORIZER, config)
2223
.objectRestore(keyName, bucketName)
2324
.execute(); //同步调用,如果要用异步调用,请用 executeAsync(...)
24-
25+
JLog.D(TAG, String.format("[res] = %s", (response == null ? "null" : response.toString())));
2526
} catch (Exception e) {
2627
e.printStackTrace();
2728
}

ufile-sample-java/src/main/java/cn/ucloud/ufile/sample/object/RenameObjectSample.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import cn.ucloud.ufile.api.ApiError;
55
import cn.ucloud.ufile.api.object.ObjectConfig;
66
import cn.ucloud.ufile.bean.UfileErrorBean;
7-
import cn.ucloud.ufile.bean.base.BaseResponseBean;
7+
import cn.ucloud.ufile.bean.base.BaseObjectResponseBean;
88
import cn.ucloud.ufile.exception.UfileClientException;
99
import cn.ucloud.ufile.exception.UfileServerException;
1010
import cn.ucloud.ufile.http.UfileCallback;
@@ -32,7 +32,7 @@ public static void main(String[] args) {
3232

3333
public static void renameObject(String bucketName, String keyName, String newKeyName, boolean isForceToCover) {
3434
try {
35-
BaseResponseBean response = UfileClient.object(Constants.OBJECT_AUTHORIZER, config)
35+
BaseObjectResponseBean response = UfileClient.object(Constants.OBJECT_AUTHORIZER, config)
3636
.renameObject(bucketName, keyName)
3737
.isRenamedTo(newKeyName)
3838
/**
@@ -56,10 +56,10 @@ public static void renameObjectAsync(String bucketName, String keyName, String n
5656
* 如果已存在同名文件,值为true则覆盖,否则操作失败;请求中若不携带该参数,默认不覆盖
5757
*/
5858
// .isForcedToCover(isForceToCover)
59-
.executeAsync(new UfileCallback<BaseResponseBean>() {
59+
.executeAsync(new UfileCallback<BaseObjectResponseBean>() {
6060

6161
@Override
62-
public void onResponse(BaseResponseBean response) {
62+
public void onResponse(BaseObjectResponseBean response) {
6363
JLog.D(TAG, String.format("[res] = %s", (response == null ? "null" : response.toString())));
6464
}
6565

ufile-sample-java/src/main/java/cn/ucloud/ufile/sample/object/SwitchStorageTypeSample.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import cn.ucloud.ufile.api.ApiError;
55
import cn.ucloud.ufile.api.object.ObjectConfig;
66
import cn.ucloud.ufile.bean.UfileErrorBean;
7-
import cn.ucloud.ufile.bean.base.BaseResponseBean;
7+
import cn.ucloud.ufile.bean.base.BaseObjectResponseBean;
88
import cn.ucloud.ufile.exception.UfileClientException;
99
import cn.ucloud.ufile.exception.UfileServerException;
1010
import cn.ucloud.ufile.http.UfileCallback;
@@ -34,7 +34,7 @@ public static void main(String[] args) {
3434

3535
public static void switchStorageType(String bucketName, String keyName, String storageType) {
3636
try {
37-
BaseResponseBean response = UfileClient.object(Constants.OBJECT_AUTHORIZER, config)
37+
BaseObjectResponseBean response = UfileClient.object(Constants.OBJECT_AUTHORIZER, config)
3838
.switchStorageType(bucketName, keyName)
3939
.turnTypeTo(storageType)
4040
.execute();
@@ -50,10 +50,10 @@ public static void switchStorageTypeAsync(String bucketName, String keyName, Str
5050
UfileClient.object(Constants.OBJECT_AUTHORIZER, config)
5151
.switchStorageType(bucketName, keyName)
5252
.turnTypeTo(storageType)
53-
.executeAsync(new UfileCallback<BaseResponseBean>() {
53+
.executeAsync(new UfileCallback<BaseObjectResponseBean>() {
5454

5555
@Override
56-
public void onResponse(BaseResponseBean response) {
56+
public void onResponse(BaseObjectResponseBean response) {
5757
JLog.D(TAG, String.format("[res] = %s", (response == null ? "null" : response.toString())));
5858
}
5959

ufile-sample-java/src/main/java/cn/ucloud/ufile/sample/object/UploadHitSample.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import cn.ucloud.ufile.UfileClient;
44
import cn.ucloud.ufile.api.ApiError;
55
import cn.ucloud.ufile.api.object.ObjectConfig;
6-
import cn.ucloud.ufile.bean.base.BaseResponseBean;
6+
import cn.ucloud.ufile.bean.base.BaseObjectResponseBean;
77
import cn.ucloud.ufile.bean.UfileErrorBean;
88
import cn.ucloud.ufile.exception.UfileClientException;
99
import cn.ucloud.ufile.exception.UfileServerException;
@@ -35,7 +35,7 @@ public static void main(String[] args) {
3535

3636
public static void uploadHitFile(File file, String nameAs, String toBucket) {
3737
try {
38-
BaseResponseBean response = UfileClient.object(Constants.OBJECT_AUTHORIZER, config)
38+
BaseObjectResponseBean response = UfileClient.object(Constants.OBJECT_AUTHORIZER, config)
3939
.uploadHit(file)
4040
.nameAs(nameAs)
4141
.toBucket(toBucket)
@@ -53,10 +53,10 @@ public static void uploadHitFileAsync(File file, String nameAs, String toBucket)
5353
.uploadHit(file)
5454
.nameAs(nameAs)
5555
.toBucket(toBucket)
56-
.executeAsync(new UfileCallback<BaseResponseBean>() {
56+
.executeAsync(new UfileCallback<BaseObjectResponseBean>() {
5757

5858
@Override
59-
public void onResponse(BaseResponseBean response) {
59+
public void onResponse(BaseObjectResponseBean response) {
6060
JLog.D(TAG, String.format("[res] = %s", (response == null ? "null" : response.toString())));
6161
}
6262

@@ -71,7 +71,7 @@ public void onError(Request request, ApiError error, UfileErrorBean response) {
7171

7272
public static void uploadHitStream(InputStream stream, String nameAs, String toBucket) {
7373
try {
74-
BaseResponseBean response = UfileClient.object(Constants.OBJECT_AUTHORIZER, config)
74+
BaseObjectResponseBean response = UfileClient.object(Constants.OBJECT_AUTHORIZER, config)
7575
.uploadHit(stream)
7676
.nameAs(nameAs)
7777
.toBucket(toBucket)
@@ -89,10 +89,10 @@ public static void uploadHitStreamAsync(InputStream stream, String nameAs, Strin
8989
.uploadHit(stream)
9090
.nameAs(nameAs)
9191
.toBucket(toBucket)
92-
.executeAsync(new UfileCallback<BaseResponseBean>() {
92+
.executeAsync(new UfileCallback<BaseObjectResponseBean>() {
9393

9494
@Override
95-
public void onResponse(BaseResponseBean response) {
95+
public void onResponse(BaseObjectResponseBean response) {
9696
JLog.D(TAG, String.format("[res] = %s", (response == null ? "null" : response.toString())));
9797
}
9898

ufile-sample-java/src/main/java/cn/ucloud/ufile/sample/object/multi/MultiUploadSample.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import cn.ucloud.ufile.api.object.policy.PutPolicy;
99
import cn.ucloud.ufile.api.object.policy.PutPolicyForCallback;
1010
import cn.ucloud.ufile.bean.MultiUploadResponse;
11+
import cn.ucloud.ufile.bean.base.BaseObjectResponseBean;
1112
import cn.ucloud.ufile.bean.base.BaseResponseBean;
1213
import cn.ucloud.ufile.exception.UfileClientException;
1314
import cn.ucloud.ufile.exception.UfileServerException;
@@ -152,7 +153,7 @@ public void onProgress(long bytesWritten, long contentLength) {
152153

153154
public static void abortMultiUpload(MultiUploadInfo info) {
154155
try {
155-
BaseResponseBean abortRes = UfileClient.object(Constants.OBJECT_AUTHORIZER, config)
156+
BaseObjectResponseBean abortRes = UfileClient.object(Constants.OBJECT_AUTHORIZER, config)
156157
.abortMultiUpload(info)
157158
.execute();
158159
JLog.D(TAG, "abort->" + abortRes.toString());

ufile/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<groupId>cn.ucloud.ufile</groupId>
88
<artifactId>ufile</artifactId>
99
<packaging>pom</packaging>
10-
<version>2.4.0</version>
10+
<version>2.4.1</version>
1111

1212
<modules>
1313
<module>ufile-core</module>

0 commit comments

Comments
 (0)