use of com.aliyun.oss.common.comm.RequestMessage in project aliyun-oss-java-sdk by aliyun.
the class OSSObjectOperation method deleteObject.
/**
* Delete an object.
*/
public void deleteObject(GenericRequest genericRequest) throws OSSException, ClientException {
assertParameterNotNull(genericRequest, "genericRequest");
String bucketName = genericRequest.getBucketName();
String key = genericRequest.getKey();
assertParameterNotNull(bucketName, "bucketName");
ensureBucketNameValid(bucketName);
assertParameterNotNull(key, "key");
ensureObjectKeyValid(key);
RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint()).setMethod(HttpMethod.DELETE).setBucket(bucketName).setKey(key).setOriginalRequest(genericRequest).build();
doOperation(request, emptyResponseParser, bucketName, key);
}
use of com.aliyun.oss.common.comm.RequestMessage in project aliyun-oss-java-sdk by aliyun.
the class OSSObjectOperation method deleteObjects.
/**
* Delete multiple objects.
*/
public DeleteObjectsResult deleteObjects(DeleteObjectsRequest deleteObjectsRequest) {
assertParameterNotNull(deleteObjectsRequest, "deleteObjectsRequest");
String bucketName = deleteObjectsRequest.getBucketName();
assertParameterNotNull(bucketName, "bucketName");
ensureBucketNameValid(bucketName);
Map<String, String> params = new HashMap<String, String>();
params.put(SUBRESOURCE_DELETE, null);
byte[] rawContent = deleteObjectsRequestMarshaller.marshall(deleteObjectsRequest);
Map<String, String> headers = new HashMap<String, String>();
addDeleteObjectsRequiredHeaders(headers, rawContent);
addDeleteObjectsOptionalHeaders(headers, deleteObjectsRequest);
RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint()).setMethod(HttpMethod.POST).setBucket(bucketName).setParameters(params).setHeaders(headers).setInputSize(rawContent.length).setInputStream(new ByteArrayInputStream(rawContent)).setOriginalRequest(deleteObjectsRequest).build();
return doOperation(request, deleteObjectsResponseParser, bucketName, null, true);
}
use of com.aliyun.oss.common.comm.RequestMessage in project aliyun-oss-java-sdk by aliyun.
the class OSSObjectOperation method getSimplifiedObjectMeta.
/**
* Get simplified object meta.
*/
public SimplifiedObjectMeta getSimplifiedObjectMeta(GenericRequest genericRequest) {
assertParameterNotNull(genericRequest, "genericRequest");
String bucketName = genericRequest.getBucketName();
String key = genericRequest.getKey();
assertParameterNotNull(bucketName, "bucketName");
assertParameterNotNull(key, "key");
ensureBucketNameValid(bucketName);
ensureObjectKeyValid(key);
Map<String, String> params = new HashMap<String, String>();
params.put(SUBRESOURCE_OBJECTMETA, null);
RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint()).setMethod(HttpMethod.GET).setBucket(bucketName).setKey(key).setParameters(params).setOriginalRequest(genericRequest).build();
return doOperation(request, getSimplifiedObjectMetaResponseParser, bucketName, key, true);
}
use of com.aliyun.oss.common.comm.RequestMessage in project aliyun-oss-java-sdk by aliyun.
the class OSSObjectOperation method restoreObject.
public RestoreObjectResult restoreObject(GenericRequest genericRequest) throws OSSException, ClientException {
assertParameterNotNull(genericRequest, "genericRequest");
String bucketName = genericRequest.getBucketName();
String key = genericRequest.getKey();
assertParameterNotNull(bucketName, "bucketName");
ensureBucketNameValid(bucketName);
assertParameterNotNull(key, "key");
ensureObjectKeyValid(key);
Map<String, String> params = new HashMap<String, String>();
params.put(RequestParameters.SUBRESOURCE_RESTORE, null);
RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint()).setMethod(HttpMethod.POST).setBucket(bucketName).setKey(key).setParameters(params).setInputStream(new ByteArrayInputStream(new byte[0])).setInputSize(0).setOriginalRequest(genericRequest).build();
return doOperation(request, ResponseParsers.restoreObjectResponseParser, bucketName, key);
}
use of com.aliyun.oss.common.comm.RequestMessage in project aliyun-oss-java-sdk by aliyun.
the class OSSObjectOperation method createSymlink.
public void createSymlink(CreateSymlinkRequest createSymlinkRequest) throws OSSException, ClientException {
assertParameterNotNull(createSymlinkRequest, "createSymlinkRequest");
String bucketName = createSymlinkRequest.getBucketName();
String symlink = createSymlinkRequest.getSymlink();
String target = createSymlinkRequest.getTarget();
assertParameterNotNull(bucketName, "bucketName");
assertParameterNotNull(symlink, "symlink");
assertParameterNotNull(target, "target");
ensureBucketNameValid(bucketName);
ensureObjectKeyValid(symlink);
ensureObjectKeyValid(target);
ObjectMetadata metadata = createSymlinkRequest.getMetadata();
if (metadata == null) {
metadata = new ObjectMetadata();
}
// 设置链接的目标文件
String encodeTargetObject = HttpUtil.urlEncode(target, DEFAULT_CHARSET_NAME);
metadata.setHeader(OSSHeaders.OSS_HEADER_SYMLINK_TARGET, encodeTargetObject);
// 设置链接文件的ContentType,目标文件优先,然后是链接文件
if (metadata.getContentType() == null) {
metadata.setContentType(Mimetypes.getInstance().getMimetype(target, symlink));
}
Map<String, String> headers = new HashMap<String, String>();
populateRequestMetadata(headers, metadata);
Map<String, String> params = new HashMap<String, String>();
params.put(SUBRESOURCE_SYMLINK, null);
RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint()).setMethod(HttpMethod.PUT).setBucket(bucketName).setKey(symlink).setHeaders(headers).setParameters(params).setOriginalRequest(createSymlinkRequest).build();
doOperation(request, emptyResponseParser, bucketName, symlink);
}
Aggregations