Skip to content

Commit 05595a3

Browse files
author
joshua.yin
authored
Merge branch 'master' into master
2 parents 31718ea + 3816dea commit 05595a3

3 files changed

Lines changed: 98 additions & 5 deletions

File tree

.gitignore

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
*.DS_Store
22
out
3-
target/
3+
target
44
.gradle
55
.idea
6-
build/
6+
build
77
*.iml
8-
classes/
8+
.classpath
9+
.project
10+
.settings/

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# UCloud Ufile SDK for Java
1+
# UCloud US3 (原名UFile) SDK for Java
22

33
[![](https://img.shields.io/github/release/ucloud/ufile-sdk-java.svg)](https://github.com/ucloud/ufile-sdk-java)
44
[![](https://img.shields.io/github/last-commit/ucloud/ufile-sdk-java.svg)](https://github.com/ucloud/ufile-sdk-java)
@@ -43,7 +43,7 @@
4343
## 快速入门
4444

4545
- 基本说明:
46-
- 所有Ufile所有API均包含同步执行(execute)和异步执行(executeAsync)两种执行方式。
46+
- 所有API均包含同步执行(execute)和异步执行(executeAsync)两种执行方式。
4747

4848
- 同步执行会返回指定的业务结果类,若执行出错则会抛出UfileException为父类的异常;
4949

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package cn.ucloud.ufile.sample.object;
2+
3+
import cn.ucloud.ufile.UfileClient;
4+
import cn.ucloud.ufile.api.object.ObjectConfig;
5+
import cn.ucloud.ufile.bean.ObjectProfile;
6+
import cn.ucloud.ufile.exception.UfileClientException;
7+
import cn.ucloud.ufile.exception.UfileServerException;
8+
import cn.ucloud.ufile.sample.Constants;
9+
import cn.ucloud.ufile.util.Etag;
10+
import cn.ucloud.ufile.util.JLog;
11+
12+
import java.io.*;
13+
14+
/**
15+
* @author: clark.liu
16+
* @E-mail: clark.liu@ucloud.cn
17+
* @date: 2021-02-23
18+
*/
19+
public class ObjectETagSample {
20+
private static final String TAG = "GetObjectETagSample";
21+
private static ObjectConfig config = new ObjectConfig("cn-sh2", "ufileos.com");
22+
23+
public static void main(String[] args) {
24+
computeLocalFileETag();
25+
// computeLocalFileETagUseStream();
26+
// getBucketObjectETag();
27+
// compareETag();
28+
}
29+
30+
public static void computeLocalFileETag() {
31+
String path = "";
32+
try {
33+
File file = new File(path);
34+
Etag etag = Etag.etag(file);
35+
JLog.D(TAG, String.format("ETag is [%s]: file path [%s]", etag.geteTag(), path));
36+
} catch (IOException e) {
37+
e.printStackTrace();
38+
}
39+
}
40+
41+
public static void computeLocalFileETagUseStream() {
42+
String path = "";
43+
try {
44+
InputStream in = new FileInputStream(path);
45+
Etag etag = Etag.etag(in);
46+
JLog.D(TAG, String.format("ETag is [%s]: file path [%s]", etag.geteTag(), path));
47+
} catch (IOException e) {
48+
e.printStackTrace();
49+
}
50+
}
51+
52+
public static void getBucketObjectETag() {
53+
String keyName = "";
54+
String bucketName = "";
55+
56+
try {
57+
ObjectProfile objectProfile = UfileClient.object(Constants.OBJECT_AUTHORIZER, config)
58+
.objectProfile(keyName, bucketName).execute();
59+
60+
if (objectProfile == null) {
61+
JLog.D(TAG, String.format("key [%s] may be not exist", keyName));
62+
return;
63+
}
64+
65+
JLog.D(TAG, String.format("key [%s] ETag: %s", keyName, objectProfile.geteTag()));
66+
} catch (UfileClientException e) {
67+
e.printStackTrace();
68+
} catch (UfileServerException e) {
69+
e.printStackTrace();
70+
}
71+
}
72+
73+
public static void compareETag() {
74+
String keyName = "";
75+
String bucketName = "";
76+
String localpath = "";
77+
78+
try {
79+
File f = new File(localpath);
80+
if (UfileClient.object(Constants.OBJECT_AUTHORIZER, config).compareEtag(f, keyName, bucketName)) {
81+
JLog.D(TAG, "ETag compare success");
82+
} else {
83+
JLog.D(TAG, "ETag compare fail");
84+
}
85+
} catch (UfileClientException e) {
86+
e.printStackTrace();
87+
} catch (UfileServerException e) {
88+
e.printStackTrace();
89+
}
90+
}
91+
}

0 commit comments

Comments
 (0)