Search in sources :

Example 1 with RequestMessage

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);
}
Also used : RequestMessage(com.aliyun.oss.common.comm.RequestMessage)

Example 2 with RequestMessage

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);
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) RequestMessage(com.aliyun.oss.common.comm.RequestMessage)

Example 3 with RequestMessage

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);
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) RequestMessage(com.aliyun.oss.common.comm.RequestMessage)

Example 4 with RequestMessage

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);
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) RequestMessage(com.aliyun.oss.common.comm.RequestMessage)

Example 5 with RequestMessage

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);
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) RequestMessage(com.aliyun.oss.common.comm.RequestMessage) ObjectMetadata(com.aliyun.oss.model.ObjectMetadata)

Aggregations

RequestMessage (com.aliyun.oss.common.comm.RequestMessage)98 LinkedHashMap (java.util.LinkedHashMap)88 HashMap (java.util.HashMap)78 ByteArrayInputStream (java.io.ByteArrayInputStream)23 ClientException (com.aliyun.oss.ClientException)9 ClientConfiguration (com.aliyun.oss.ClientConfiguration)6 ResponseHandler (com.aliyun.oss.common.comm.ResponseHandler)6 InputStream (java.io.InputStream)6 ResponseMessage (com.aliyun.oss.common.comm.ResponseMessage)5 IOUtils.newRepeatableInputStream (com.aliyun.oss.common.utils.IOUtils.newRepeatableInputStream)5 ProgressListener (com.aliyun.oss.event.ProgressListener)5 ArrayList (java.util.ArrayList)5 ExecutionContext (com.aliyun.oss.common.comm.ExecutionContext)4 ProgressInputStream (com.aliyun.oss.event.ProgressInputStream)4 URI (java.net.URI)4 CheckedInputStream (java.util.zip.CheckedInputStream)4 ServiceException (com.aliyun.oss.ServiceException)3 IOException (java.io.IOException)3 Test (org.junit.Test)3 Credentials (com.aliyun.oss.common.auth.Credentials)2