Skip to content

Commit 1eac4a6

Browse files
authored
Merge branch 'tencentyun:master' into master
2 parents 19be454 + 39e76a5 commit 1eac4a6

12 files changed

+397
-3
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>com.qcloud</groupId>
66
<artifactId>cos_api</artifactId>
7-
<version>5.6.97</version>
7+
<version>5.6.98</version>
88
<packaging>jar</packaging>
99
<name>cos-java-sdk</name>
1010
<description>java sdk for qcloud cos</description>

src/main/java/com/qcloud/cos/COS.java

+22
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,28 @@ public COSObject getObject(GetObjectRequest getObjectRequest)
375375
public ObjectMetadata getObject(GetObjectRequest getObjectRequest, File destinationFile)
376376
throws CosClientException, CosServiceException;
377377

378+
/**
379+
* <p>
380+
* Create a Symlink for the specified object.
381+
* The <code>PutSymlinkRequest</code> contains all the details of the request, including the bucket created to,
382+
* the symLink name referred to the target object, the target object key.
383+
* <p/>
384+
* @param putSymlinkRequest the request object containing all the parameter to create a symlink.
385+
* @return the result creating symlink.
386+
*/
387+
public PutSymlinkResult putSymlink(PutSymlinkRequest putSymlinkRequest);
388+
389+
/**
390+
* <p>
391+
* Get the object the symbolic link actually points to.
392+
* The <code>GetSymlinkRequest</code> contains all the details of the request, including the bucket created to,
393+
* the symbolic link queried.
394+
* </p>
395+
* @param getSymlinkRequest the request object containing all the parameter to get a symlink.
396+
* @return the target the symbolic link referred to.
397+
*/
398+
public GetSymlinkResult getSymlink(GetSymlinkRequest getSymlinkRequest);
399+
378400
/**
379401
* @param bucketName Name of bucket that presumably contains object
380402
* @param objectName Name of object that has to be checked

src/main/java/com/qcloud/cos/COSClient.java

+33-2
Original file line numberDiff line numberDiff line change
@@ -1183,6 +1183,39 @@ public COSObject getCOSObjectStream() {
11831183
return cosObject.getObjectMetadata();
11841184
}
11851185

1186+
@Override
1187+
public PutSymlinkResult putSymlink(PutSymlinkRequest putSymlinkRequest) {
1188+
rejectNull(putSymlinkRequest, "The request must not be null.");
1189+
rejectNull(putSymlinkRequest.getBucketName(),
1190+
"The bucket name parameter must be specified when create symlink.");
1191+
rejectNull(putSymlinkRequest.getSymlink(), "The symlink name must be specified when create symlink");
1192+
rejectNull(putSymlinkRequest.getTarget(), "The target object must be specified when create symlink");
1193+
1194+
CosHttpRequest<CosServiceRequest> request = createRequest(putSymlinkRequest.getBucketName(),
1195+
putSymlinkRequest.getSymlink(), putSymlinkRequest, HttpMethodName.PUT);
1196+
request.addParameter("symlink", null);
1197+
1198+
request.addHeader(Headers.SYMLINK_TARGET, putSymlinkRequest.getTarget());
1199+
1200+
return invoke(request, new PutSymlinkResultHandler());
1201+
}
1202+
1203+
@Override
1204+
public GetSymlinkResult getSymlink(GetSymlinkRequest getSymlinkRequest) {
1205+
rejectNull(getSymlinkRequest, "The request must not be null.");
1206+
rejectNull(getSymlinkRequest.getBucketName(),
1207+
"The bucket name parameter must be specified when getting symlink.");
1208+
rejectNull(getSymlinkRequest.getSymlink(), "The requested symbolic link must be specified.");
1209+
1210+
CosHttpRequest<CosServiceRequest> request = createRequest(getSymlinkRequest.getBucketName(),
1211+
getSymlinkRequest.getSymlink(), getSymlinkRequest, HttpMethodName.GET);
1212+
request.addParameter("symlink", null);
1213+
addParameterIfNotNull(request,"versionId", getSymlinkRequest.getVersionId());
1214+
1215+
return invoke(request, new GetSymlinkResultHandler());
1216+
}
1217+
1218+
11861219
@Override
11871220
public boolean doesObjectExist(String bucketName, String objectName)
11881221
throws CosClientException, CosServiceException {
@@ -1694,8 +1727,6 @@ public void abortMultipartUpload(AbortMultipartUploadRequest abortMultipartUploa
16941727

16951728
}
16961729

1697-
1698-
16991730
@Override
17001731
public CompleteMultipartUploadResult completeMultipartUpload(
17011732
CompleteMultipartUploadRequest completeMultipartUploadRequest)

src/main/java/com/qcloud/cos/Headers.java

+2
Original file line numberDiff line numberDiff line change
@@ -327,4 +327,6 @@ public interface Headers {
327327
public static final String ENCRYPTION_UNENCRYPTED_CONTENT_MD5 = "client-side-encryption-unencrypted-content-md5";
328328
public static final String ENCRYPTION_DATA_SIZE = "client-side-encryption-data-size";
329329
public static final String ENCRYPTION_PART_SIZE = "client-side-encryption-part-size";
330+
331+
public static final String SYMLINK_TARGET= "x-cos-symlink-target";
330332
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.qcloud.cos.demo;
2+
3+
import com.qcloud.cos.COSClient;
4+
import com.qcloud.cos.ClientConfig;
5+
import com.qcloud.cos.auth.BasicCOSCredentials;
6+
import com.qcloud.cos.auth.COSCredentials;
7+
import com.qcloud.cos.model.PutSymlinkRequest;
8+
import com.qcloud.cos.model.PutSymlinkResult;
9+
import com.qcloud.cos.region.Region;
10+
11+
public class CreateSymlinkDemo {
12+
13+
private static final String secretId = "";
14+
private static final String secretKey = "";
15+
private static final String bucket = "";
16+
private static final String region = "";
17+
18+
public static void createSymlink(String symlink, String target) {
19+
COSCredentials cosCredentials = new BasicCOSCredentials(secretId, secretKey);
20+
ClientConfig clientConfig = new ClientConfig(new Region(region));
21+
22+
COSClient cosClient = new COSClient(cosCredentials, clientConfig);
23+
24+
PutSymlinkRequest putSymlinkRequest = new PutSymlinkRequest(bucket, symlink, target);
25+
26+
try {
27+
PutSymlinkResult putSymlinkResult = cosClient.putSymlink(putSymlinkRequest);
28+
System.out.println("ETag: " + putSymlinkResult.getETag());
29+
} finally {
30+
cosClient.shutdown();
31+
}
32+
33+
}
34+
35+
public static void main(String[] args) {
36+
createSymlink("test-symlink", "word_count.txt");
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.qcloud.cos.demo;
2+
3+
import com.qcloud.cos.COSClient;
4+
import com.qcloud.cos.ClientConfig;
5+
import com.qcloud.cos.auth.BasicCOSCredentials;
6+
import com.qcloud.cos.auth.COSCredentials;
7+
import com.qcloud.cos.model.GetSymlinkRequest;
8+
import com.qcloud.cos.model.GetSymlinkResult;
9+
import com.qcloud.cos.region.Region;
10+
11+
public class GetSymlinkDemo {
12+
private static final String secretId = "";
13+
private static final String secretKey = "";
14+
private static final String bucket = "";
15+
private static final String region = "";
16+
17+
public static String getSymlink(String symlink) {
18+
COSCredentials cosCredentials = new BasicCOSCredentials(secretId, secretKey);
19+
ClientConfig clientConfig = new ClientConfig(new Region(region));
20+
COSClient cosClient = new COSClient(cosCredentials, clientConfig);
21+
22+
GetSymlinkResult getSymlinkResult = cosClient.getSymlink(
23+
new GetSymlinkRequest(bucket, symlink, null));
24+
25+
return getSymlinkResult.getTarget();
26+
}
27+
28+
public static void main(String[] args) {
29+
System.out.println(getSymlink("test-symlink"));
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.qcloud.cos.model;
2+
3+
import com.qcloud.cos.internal.CosServiceRequest;
4+
5+
import java.io.Serializable;
6+
7+
public class GetSymlinkRequest extends CosServiceRequest implements Serializable {
8+
private static final long serialVersionUID = -1413983172326934188L;
9+
10+
private String bucketName;
11+
private String symlink;
12+
private String versionId;
13+
14+
public GetSymlinkRequest() {
15+
}
16+
17+
public GetSymlinkRequest(String bucketName, String symlink, String versionId) {
18+
this.bucketName = bucketName;
19+
this.symlink = symlink;
20+
this.versionId = versionId;
21+
}
22+
23+
public GetSymlinkRequest withBucketName(String bucketName) {
24+
this.bucketName = bucketName;
25+
return this;
26+
}
27+
28+
public GetSymlinkRequest withSymlink(String symlink) {
29+
this.symlink = symlink;
30+
return this;
31+
}
32+
33+
public GetSymlinkRequest withVersionId(String versionId) {
34+
this.versionId = versionId;
35+
return this;
36+
}
37+
38+
public String getBucketName() {
39+
return bucketName;
40+
}
41+
42+
public void setBucketName(String bucketName) {
43+
this.bucketName = bucketName;
44+
}
45+
46+
public String getSymlink() {
47+
return symlink;
48+
}
49+
50+
public void setSymlink(String symlink) {
51+
this.symlink = symlink;
52+
}
53+
54+
public String getVersionId() {
55+
return versionId;
56+
}
57+
58+
public void setVersionId(String versionId) {
59+
this.versionId = versionId;
60+
}
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.qcloud.cos.model;
2+
3+
import java.io.Serializable;
4+
5+
public class GetSymlinkResult implements Serializable {
6+
private static final long serialVersionUID = 3524820691299905321L;
7+
8+
private String requestId;
9+
private String ETag;
10+
private String target;
11+
12+
public String getRequestId() {
13+
return requestId;
14+
}
15+
16+
public void setRequestId(String requestId) {
17+
this.requestId = requestId;
18+
}
19+
20+
public String getETag() {
21+
return ETag;
22+
}
23+
24+
public void setETag(String ETag) {
25+
this.ETag = ETag;
26+
}
27+
28+
public String getTarget() {
29+
return target;
30+
}
31+
32+
public void setTarget(String target) {
33+
this.target = target;
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.qcloud.cos.model;
2+
3+
import com.qcloud.cos.Headers;
4+
import com.qcloud.cos.http.CosHttpResponse;
5+
import com.qcloud.cos.internal.AbstractCosResponseHandler;
6+
import com.qcloud.cos.internal.CosServiceResponse;
7+
8+
import java.util.Map;
9+
10+
public class GetSymlinkResultHandler extends AbstractCosResponseHandler<GetSymlinkResult> {
11+
@Override
12+
public CosServiceResponse<GetSymlinkResult> handle(CosHttpResponse response) throws Exception {
13+
GetSymlinkResult getSymlinkResult = new GetSymlinkResult();
14+
final CosServiceResponse<GetSymlinkResult> cosServiceResponse = new CosServiceResponse<>();
15+
for (Map.Entry<String, String> header : response.getHeaders().entrySet()) {
16+
String key = header.getKey();
17+
String value = header.getValue();
18+
19+
if (Headers.REQUEST_ID.compareToIgnoreCase(key) == 0) {
20+
getSymlinkResult.setRequestId(value);
21+
continue;
22+
}
23+
24+
if (Headers.ETAG.compareToIgnoreCase(key) == 0) {
25+
getSymlinkResult.setETag(value);
26+
continue;
27+
}
28+
29+
if (Headers.SYMLINK_TARGET.compareToIgnoreCase(key) == 0) {
30+
getSymlinkResult.setTarget(value);
31+
}
32+
}
33+
34+
cosServiceResponse.setResult(getSymlinkResult);
35+
return cosServiceResponse;
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.qcloud.cos.model;
2+
3+
import com.qcloud.cos.internal.CosServiceRequest;
4+
5+
import java.io.Serializable;
6+
7+
public class PutSymlinkRequest extends CosServiceRequest implements Serializable {
8+
private static final long serialVersionUID = 2696244667516350971L;
9+
private String bucketName;
10+
private String symlink;
11+
private String target;
12+
13+
public PutSymlinkRequest() {
14+
}
15+
16+
public PutSymlinkRequest(String bucketName, String symlink, String target) {
17+
this.bucketName = bucketName;
18+
this.symlink = symlink;
19+
this.target = target;
20+
}
21+
22+
public PutSymlinkRequest withBucketName(String bucketName) {
23+
this.bucketName = bucketName;
24+
return this;
25+
}
26+
27+
public PutSymlinkRequest withSymlink(String symlink) {
28+
this.symlink = symlink;
29+
return this;
30+
}
31+
32+
public PutSymlinkRequest withTarget(String target) {
33+
this.target = target;
34+
return this;
35+
}
36+
37+
public String getBucketName() {
38+
return bucketName;
39+
}
40+
41+
public void setBucketName(String bucketName) {
42+
this.bucketName = bucketName;
43+
}
44+
45+
public String getSymlink() {
46+
return symlink;
47+
}
48+
49+
public void setSymlink(String symlink) {
50+
this.symlink = symlink;
51+
}
52+
53+
public String getTarget() {
54+
return target;
55+
}
56+
57+
public void setTarget(String target) {
58+
this.target = target;
59+
}
60+
}

0 commit comments

Comments
 (0)