本文整理汇总了Java中com.qcloud.cos.exception.CosClientException类的典型用法代码示例。如果您正苦于以下问题:Java CosClientException类的具体用法?Java CosClientException怎么用?Java CosClientException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CosClientException类属于com.qcloud.cos.exception包,在下文中一共展示了CosClientException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: listNextBatchOfObjects
import com.qcloud.cos.exception.CosClientException; //导入依赖的package包/类
@Override
public ObjectListing listNextBatchOfObjects(
ListNextBatchOfObjectsRequest listNextBatchOfObjectsRequest)
throws CosClientException, CosServiceException {
rejectNull(listNextBatchOfObjectsRequest,
"The request object parameter must be specified when listing the next batch of objects in a bucket");
ObjectListing previousObjectListing =
listNextBatchOfObjectsRequest.getPreviousObjectListing();
if (!previousObjectListing.isTruncated()) {
ObjectListing emptyListing = new ObjectListing();
emptyListing.setBucketName(previousObjectListing.getBucketName());
emptyListing.setDelimiter(previousObjectListing.getDelimiter());
emptyListing.setMarker(previousObjectListing.getNextMarker());
emptyListing.setMaxKeys(previousObjectListing.getMaxKeys());
emptyListing.setPrefix(previousObjectListing.getPrefix());
emptyListing.setEncodingType(previousObjectListing.getEncodingType());
emptyListing.setTruncated(false);
return emptyListing;
}
return listObjects(listNextBatchOfObjectsRequest.toListObjectsRequest());
}
示例2: abortMultipartUploads
import com.qcloud.cos.exception.CosClientException; //导入依赖的package包/类
/**
* <p>
* Aborts any multipart uploads that were initiated before the specified date.
* </p>
* <p>
* This method is useful for cleaning up any interrupted multipart uploads.
* <code>TransferManager</code> attempts to abort any failed uploads, but in some cases this may
* not be possible, such as if network connectivity is completely lost.
* </p>
*
* @param bucketName The name of the bucket containing the multipart uploads to abort.
* @param date The date indicating which multipart uploads should be aborted.
*/
public void abortMultipartUploads(String bucketName, Date date)
throws CosServiceException, CosClientException {
MultipartUploadListing uploadListing = cos.listMultipartUploads(
appendSingleObjectUserAgent(new ListMultipartUploadsRequest(bucketName)));
do {
for (MultipartUpload upload : uploadListing.getMultipartUploads()) {
if (upload.getInitiated().compareTo(date) < 0) {
cos.abortMultipartUpload(
appendSingleObjectUserAgent(new AbortMultipartUploadRequest(bucketName,
upload.getKey(), upload.getUploadId())));
}
}
ListMultipartUploadsRequest request = new ListMultipartUploadsRequest(bucketName)
.withUploadIdMarker(uploadListing.getNextUploadIdMarker())
.withKeyMarker(uploadListing.getNextKeyMarker());
uploadListing = cos.listMultipartUploads(appendSingleObjectUserAgent(request));
} while (uploadListing.isTruncated());
}
示例3: convertToXmlByteArray
import com.qcloud.cos.exception.CosClientException; //导入依赖的package包/类
/**
* Converts the specified {@link DeleteObjectsRequest} object to an XML fragment that
* can be sent to Qcloud COS.
*
* @param rq
* The {@link DeleteObjectsRequest}
*/
public byte[] convertToXmlByteArray(DeleteObjectsRequest rq) throws CosClientException {
XmlWriter xml = new XmlWriter();
xml.start("Delete");
if ( rq.getQuiet() ) {
xml.start("Quiet").value("true").end();
}
for (KeyVersion keyVersion : rq.getKeys()) {
writeKeyVersion(xml, keyVersion);
}
xml.end();
return xml.getBytes();
}
示例4: setBucketAcl
import com.qcloud.cos.exception.CosClientException; //导入依赖的package包/类
@Override
public void setBucketAcl(SetBucketAclRequest setBucketAclRequest)
throws CosClientException, CosServiceException {
String bucketName = setBucketAclRequest.getBucketName();
rejectNull(bucketName,
"The bucket name parameter must be specified when setting a bucket's ACL");
AccessControlList acl = setBucketAclRequest.getAcl();
CannedAccessControlList cannedAcl = setBucketAclRequest.getCannedAcl();
if (acl == null && cannedAcl == null) {
throw new IllegalArgumentException(
"The ACL parameter must be specified when setting a bucket's ACL");
}
if (acl != null && cannedAcl != null) {
throw new IllegalArgumentException(
"Only one of the acl and cannedAcl parameter can be specified, not both.");
}
if (acl != null) {
setAcl(bucketName, null, null, acl, setBucketAclRequest);
} else {
setAcl(bucketName, null, null, cannedAcl, setBucketAclRequest);
}
}
示例5: getBucketReplicationConfiguration
import com.qcloud.cos.exception.CosClientException; //导入依赖的package包/类
@Override
public BucketReplicationConfiguration getBucketReplicationConfiguration(
GetBucketReplicationConfigurationRequest getBucketReplicationConfigurationRequest)
throws CosClientException, CosServiceException {
rejectNull(getBucketReplicationConfigurationRequest,
"The bucket request parameter must be specified when retrieving replication configuration");
String bucketName = getBucketReplicationConfigurationRequest.getBucketName();
rejectNull(bucketName,
"The bucket request must specify a bucket name when retrieving replication configuration");
CosHttpRequest<GetBucketReplicationConfigurationRequest> request = createRequest(bucketName,
null, getBucketReplicationConfigurationRequest, HttpMethodName.GET);
request.addParameter("replication", null);
return invoke(request, new Unmarshallers.BucketReplicationConfigurationUnmarshaller());
}
示例6: deleteBucketLifecycleConfiguration
import com.qcloud.cos.exception.CosClientException; //导入依赖的package包/类
@Override
public void deleteBucketLifecycleConfiguration(
DeleteBucketLifecycleConfigurationRequest deleteBucketLifecycleConfigurationRequest)
throws CosClientException, CosServiceException {
rejectNull(deleteBucketLifecycleConfigurationRequest,
"The delete bucket lifecycle configuration request object must be specified.");
String bucketName = deleteBucketLifecycleConfigurationRequest.getBucketName();
rejectNull(bucketName,
"The bucket name parameter must be specified when deleting bucket lifecycle configuration.");
CosHttpRequest<DeleteBucketLifecycleConfigurationRequest> request = createRequest(
bucketName, null, deleteBucketLifecycleConfigurationRequest, HttpMethodName.DELETE);
request.addParameter("lifecycle", null);
invoke(request, voidCosResponseHandler);
}
示例7: collectPartETags
import com.qcloud.cos.exception.CosClientException; //导入依赖的package包/类
/**
* Collects the Part ETags for initiating the complete multi-part upload
* request. This is blocking as it waits until all the upload part threads
* complete.
*/
private List<PartETag> collectPartETags() {
final List<PartETag> partETags = new ArrayList<PartETag>();
partETags.addAll(eTagsBeforeResume);
for (Future<PartETag> future : futures) {
try {
partETags.add(future.get());
} catch (Exception e) {
throw new CosClientException(
"Unable to complete multi-part upload. Individual part upload failed : "
+ e.getCause().getMessage(), e.getCause());
}
}
return partETags;
}
示例8: getBucketCrossOriginConfiguration
import com.qcloud.cos.exception.CosClientException; //导入依赖的package包/类
@Override
public BucketCrossOriginConfiguration getBucketCrossOriginConfiguration(
GetBucketCrossOriginConfigurationRequest getBucketCrossOriginConfigurationRequest)
throws CosClientException, CosServiceException {
rejectNull(getBucketCrossOriginConfigurationRequest,
"The request object parameter getBucketCrossOriginConfigurationRequest must be specified.");
String bucketName = getBucketCrossOriginConfigurationRequest.getBucketName();
rejectNull(bucketName,
"The bucket name must be specified when retrieving the bucket cross origin configuration.");
CosHttpRequest<GetBucketCrossOriginConfigurationRequest> request = createRequest(bucketName,
null, getBucketCrossOriginConfigurationRequest, HttpMethodName.GET);
request.addParameter("cors", null);
try {
return invoke(request, new Unmarshallers.BucketCrossOriginConfigurationUnmarshaller());
} catch (CosServiceException cse) {
switch (cse.getStatusCode()) {
case 404:
return null;
default:
throw cse;
}
}
}
示例9: abortMultipartUpload
import com.qcloud.cos.exception.CosClientException; //导入依赖的package包/类
@Override
public void abortMultipartUpload(AbortMultipartUploadRequest abortMultipartUploadRequest)
throws CosClientException, CosServiceException {
rejectNull(abortMultipartUploadRequest,
"The request parameter must be specified when aborting a multipart upload");
rejectNull(abortMultipartUploadRequest.getBucketName(),
"The bucket name parameter must be specified when aborting a multipart upload");
rejectNull(abortMultipartUploadRequest.getKey(),
"The key parameter must be specified when aborting a multipart upload");
rejectNull(abortMultipartUploadRequest.getUploadId(),
"The upload ID parameter must be specified when aborting a multipart upload");
String bucketName = abortMultipartUploadRequest.getBucketName();
String key = abortMultipartUploadRequest.getKey();
CosHttpRequest<AbortMultipartUploadRequest> request =
createRequest(bucketName, key, abortMultipartUploadRequest, HttpMethodName.DELETE);
request.addParameter("uploadId", abortMultipartUploadRequest.getUploadId());
invoke(request, voidCosResponseHandler);
}
示例10: testTransferManagerUploadLocalDir
import com.qcloud.cos.exception.CosClientException; //导入依赖的package包/类
@Test
public void testTransferManagerUploadLocalDir()
throws IOException, CosServiceException, CosClientException, InterruptedException {
if (!judgeUserInfoValid()) {
return;
}
String folderPrefix = "/ut_uploaddir/";
File localFile1 = buildTestFile(1L);
File localFile2 = buildTestFile(1024L);
String key1 = folderPrefix + localFile1.getName();
String key2 = folderPrefix + localFile2.getName();
try {
MultipleFileUpload multipleFileUpload =
transferManager.uploadDirectory(bucket, folderPrefix, tmpDir, true);
multipleFileUpload.waitForCompletion();
headSimpleObject(key1, localFile1.length(), Md5Utils.md5Hex(localFile1));
headSimpleObject(key2, localFile2.length(), Md5Utils.md5Hex(localFile2));
} finally {
if (localFile1.exists()) {
assertTrue(localFile1.delete());
}
if (localFile2.exists()) {
assertTrue(localFile2.delete());
}
clearObject(key1);
clearObject(key2);
}
}
示例11: getObjectAcl
import com.qcloud.cos.exception.CosClientException; //导入依赖的package包/类
@Override
public AccessControlList getObjectAcl(GetObjectAclRequest getObjectAclRequest)
throws CosClientException, CosServiceException {
rejectNull(getObjectAclRequest,
"The request parameter must be specified when requesting an object's ACL");
rejectNull(getObjectAclRequest.getBucketName(),
"The bucket name parameter must be specified when requesting an object's ACL");
rejectNull(getObjectAclRequest.getKey(),
"The key parameter must be specified when requesting an object's ACL");
return getAcl(getObjectAclRequest.getBucketName(), getObjectAclRequest.getKey(),
getObjectAclRequest.getVersionId(), getObjectAclRequest);
}
示例12: getBucketAcl
import com.qcloud.cos.exception.CosClientException; //导入依赖的package包/类
@Override
public AccessControlList getBucketAcl(GetBucketAclRequest getBucketAclRequest)
throws CosClientException, CosServiceException {
String bucketName = getBucketAclRequest.getBucketName();
rejectNull(bucketName,
"The bucket name parameter must be specified when requesting a bucket's ACL");
return getAcl(bucketName, null, null, getBucketAclRequest);
}
示例13: convertToXmlByteArray
import com.qcloud.cos.exception.CosClientException; //导入依赖的package包/类
public byte[] convertToXmlByteArray(BucketLifecycleConfiguration config)
throws CosClientException {
XmlWriter xml = new XmlWriter();
xml.start("LifecycleConfiguration");
for (Rule rule : config.getRules()) {
writeRule(xml, rule);
}
xml.end();
return xml.getBytes();
}
示例14: read
import com.qcloud.cos.exception.CosClientException; //导入依赖的package包/类
@Override
public int read(byte[] b, int off, int len) throws IOException {
int count = 0;
while (currentPosition < requestedOffset) {
long skippedBytes = super.skip(requestedOffset - currentPosition);
if (skippedBytes == 0) {
count++;
if (count > MAX_SKIPS) {
throw new CosClientException(
"Unable to position the currentPosition from "
+ currentPosition + " to "
+ requestedOffset);
}
}
currentPosition += skippedBytes;
}
long bytesRemaining =
(requestedLength + requestedOffset) - currentPosition;
if (bytesRemaining <= 0)
return -1;
len = (int) Math.min(len, bytesRemaining);
int bytesRead = super.read(b, off, len);
currentPosition += bytesRead;
return bytesRead;
}
示例15: buildUrlAndHost
import com.qcloud.cos.exception.CosClientException; //导入依赖的package包/类
private <X extends CosServiceRequest> void buildUrlAndHost(CosHttpRequest<X> request,
String bucket, String key, boolean isServiceRequest) throws CosClientException {
key = formatKey(key);
request.setResourcePath(key);
String host = "";
if (isServiceRequest) {
host = "service.cos.myqcloud.com";
} else {
bucket = formatBucket(bucket, cred.getCOSAppId());
host = String.format("%s.%s.myqcloud.com", bucket,
formatRegion(clientConfig.getRegion().getRegionName()));
if (this.clientConfig.getEndPointSuffix() != null) {
String endPointSuffix = clientConfig.getEndPointSuffix();
if (endPointSuffix.startsWith(".")) {
host = String.format("%s%s", bucket, endPointSuffix);
} else {
host = String.format("%s.%s", bucket, endPointSuffix);
}
}
}
request.addHeader(Headers.HOST, host);
request.setProtocol(clientConfig.getHttpProtocol());
request.setEndpoint(host);
request.setResourcePath(key);
}