本文整理汇总了Java中com.amazonaws.services.s3.model.DeleteObjectRequest类的典型用法代码示例。如果您正苦于以下问题:Java DeleteObjectRequest类的具体用法?Java DeleteObjectRequest怎么用?Java DeleteObjectRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DeleteObjectRequest类属于com.amazonaws.services.s3.model包,在下文中一共展示了DeleteObjectRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: remove
import com.amazonaws.services.s3.model.DeleteObjectRequest; //导入依赖的package包/类
public void remove(Object[] params) {
AmazonS3 s3client = new AmazonS3Client(new ProfileCredentialsProvider());
try {
s3client.deleteObject(new DeleteObjectRequest(bucketName, params[0].toString()));
} catch (AmazonServiceException ase) {
System.out.println("Caught an AmazonServiceException, which " +
"means your request made it " +
"to Amazon S3, but was rejected with an error response" +
" for some reason.");
System.out.println("Error Message:" + ase.getMessage());
System.out.println("HTTP Status Code:" + ase.getStatusCode());
System.out.println("AWS Error Code:" + ase.getErrorCode());
System.out.println("Error Type:" + ase.getErrorType());
System.out.println("Request ID:" + ase.getRequestId());
} catch (AmazonClientException ace) {
System.out.println("Caught an AmazonClientException, which " +
"means the client encountered " +
"an internal error while trying to " +
"communicate with S3, " +
"such as not being able to access the network.");
System.out.println("Error Message: " + ace.getMessage());
}
}
示例2: delete
import com.amazonaws.services.s3.model.DeleteObjectRequest; //导入依赖的package包/类
@Override
public boolean delete(String hostName, Path path, boolean recursive) throws IOException {
String obj = path.toString();
if (path.toString().startsWith(hostName)) {
obj = path.toString().substring(hostName.length());
}
LOG.debug("Object name to delete {}. Path {}", obj, path.toString());
try {
mClient.deleteObject(new DeleteObjectRequest(mBucket, obj));
memoryCache.removeFileStatus(path.toString());
return true;
} catch (AmazonServiceException e) {
if (e.getStatusCode() != 404) {
throw new IOException(e);
}
}
LOG.warn("Delete on {} not found. Nothing to delete");
return false;
}
示例3: delete
import com.amazonaws.services.s3.model.DeleteObjectRequest; //导入依赖的package包/类
@Override
public void delete(ContentReference contentReference) throws ContentIOException
{
if (!isContentReferenceSupported(contentReference))
{
throw new ContentIOException("ContentReference not supported");
}
String remotePath = getRelativePath(contentReference.getUri());
try
{
s3.deleteObject(new DeleteObjectRequest(s3BucketName, remotePath));
} catch (AmazonClientException e)
{
throw new ContentIOException("Failed to delete content", e);
}
}
示例4: remove
import com.amazonaws.services.s3.model.DeleteObjectRequest; //导入依赖的package包/类
@Override
public void remove(final String key) throws IOException {
try {
final AmazonS3 aws = this.regn.aws();
final long start = System.currentTimeMillis();
aws.deleteObject(new DeleteObjectRequest(this.bkt, key));
Logger.info(
this,
"ocket '%s' removed in bucket '%s' in %[ms]s",
key, this.bkt, System.currentTimeMillis() - start
);
} catch (final AmazonServiceException ex) {
throw new IOException(
String.format(
"failed to remove '%s' bucket",
this.bkt
),
ex
);
}
}
示例5: delete
import com.amazonaws.services.s3.model.DeleteObjectRequest; //导入依赖的package包/类
/**
* Delete file from Amazon S3 storage.
*
* @param bucket
* - S3 Bucket name.
* @param key
* - S3 storage path. Example:
* DEMO/TestSuiteName/TestMethodName/file.txt
*/
public void delete(String bucket, String key) {
if (key == null) {
throw new RuntimeException("Key is null!");
}
if (key.isEmpty()) {
throw new RuntimeException("Key is empty!");
}
try {
s3client.deleteObject(new DeleteObjectRequest(bucket, key));
} catch (AmazonServiceException ase) {
LOGGER.error("Caught an AmazonServiceException, which "
+ "means your request made it "
+ "to Amazon S3, but was rejected with an error response for some reason.\n"
+ "Error Message: " + ase.getMessage() + "\n"
+ "HTTP Status Code: " + ase.getStatusCode() + "\n"
+ "AWS Error Code: " + ase.getErrorCode() + "\n"
+ "Error Type: " + ase.getErrorType() + "\n"
+ "Request ID: " + ase.getRequestId());
} catch (AmazonClientException ace) {
LOGGER.error("Caught an AmazonClientException.\n"
+ "Error Message: " + ace.getMessage());
}
}
示例6: deleteObject
import com.amazonaws.services.s3.model.DeleteObjectRequest; //导入依赖的package包/类
@Override
public void deleteObject(DeleteObjectRequest deleteObjectRequest)
throws AmazonClientException, AmazonServiceException {
String blobName = deleteObjectRequest.getKey();
if (!blobs.containsKey(blobName)) {
throw new AmazonS3Exception("[" + blobName + "] does not exist.");
}
blobs.remove(blobName);
}
示例7: handleRequest
import com.amazonaws.services.s3.model.DeleteObjectRequest; //导入依赖的package包/类
@Override
public Parameters handleRequest(Parameters parameters, Context context) {
context.getLogger().log("Input Function [" + context.getFunctionName() + "], Parameters [" + parameters + "]");
// The archive location of the snapshot will be decided by the alert
// flag
String newFilename;
if (parameters.getSendAlert()) {
newFilename = parameters.getS3Key().replace("upload/", "archive/alerts/");
} else {
newFilename = parameters.getS3Key().replace("upload/", "archive/falsepositives/");
}
// Ensure that the first two hyphens are used to create sub-directories
// in the file path
newFilename = newFilename.replaceFirst("-", "/");
newFilename = newFilename.replaceFirst("-", "/");
// Using the S3 client, first copy the file to the archive, and then
// delete the original
AmazonS3 client = AmazonS3ClientBuilder.defaultClient();
CopyObjectRequest copyObjectRequest = new CopyObjectRequest(parameters.getS3Bucket(), parameters.getS3Key(), parameters.getS3Bucket(), newFilename);
client.copyObject(copyObjectRequest);
DeleteObjectRequest deleteObjectRequest = new DeleteObjectRequest(parameters.getS3Bucket(), parameters.getS3Key());
client.deleteObject(deleteObjectRequest);
// Place the new location in the parameters
parameters.setS3ArchivedKey(newFilename);
context.getLogger().log("Output Function [" + context.getFunctionName() + "], Parameters [" + parameters + "]");
return parameters;
}
示例8: deleteObject
import com.amazonaws.services.s3.model.DeleteObjectRequest; //导入依赖的package包/类
@Override
public void deleteObject(DeleteObjectRequest deleteObjectRequest)
throws SdkClientException, AmazonServiceException {
deleteObjectRequest = beforeClientExecution(deleteObjectRequest);
rejectNull(deleteObjectRequest,
"The delete object request must be specified when deleting an object");
rejectNull(deleteObjectRequest.getBucketName(), "The bucket name must be specified when deleting an object");
rejectNull(deleteObjectRequest.getKey(), "The key must be specified when deleting an object");
Request<DeleteObjectRequest> request = createRequest(deleteObjectRequest.getBucketName(), deleteObjectRequest.getKey(), deleteObjectRequest, HttpMethodName.DELETE);
invoke(request, voidResponseHandler, deleteObjectRequest.getBucketName(), deleteObjectRequest.getKey());
}
示例9: deleteObject
import com.amazonaws.services.s3.model.DeleteObjectRequest; //导入依赖的package包/类
@Override
public void deleteObject(DeleteObjectRequest req) {
req.getRequestClientOptions().appendUserAgent(USER_AGENT);
// Delete the object
super.deleteObject(req);
// If it exists, delete the instruction file.
InstructionFileId ifid = new S3ObjectId(req.getBucketName(), req.getKey()).instructionFileId();
DeleteObjectRequest instructionDeleteRequest = (DeleteObjectRequest) req.clone();
instructionDeleteRequest.withBucketName(ifid.getBucket()).withKey(ifid.getKey());
super.deleteObject(instructionDeleteRequest);
}
示例10: removeAllObjects
import com.amazonaws.services.s3.model.DeleteObjectRequest; //导入依赖的package包/类
private void removeAllObjects() {
amazonS3.listObjects(bucketName)
.getObjectSummaries()
.forEach(s3ObjectSummary -> {
DeleteObjectRequest request = new DeleteObjectRequest(bucketName, s3ObjectSummary.getKey());
amazonS3.deleteObject(request);
});
}
示例11: delete
import com.amazonaws.services.s3.model.DeleteObjectRequest; //导入依赖的package包/类
@Override
public void delete(String path) throws BusinessException {
if (!Optional.ofNullable(path).isPresent()) {
throw new BusinessException(Validations.INVALID_PATH.getCode());
}
client.getClient(credentials.getCredentials());
try {
s3Client.deleteObject(
new DeleteObjectRequest(cdnConfig.getName(), path)
);
} catch (AmazonServiceException e) {
throw new BusinessException(e.getMessage());
}
}
示例12: moveObject
import com.amazonaws.services.s3.model.DeleteObjectRequest; //导入依赖的package包/类
@Override
public CompletableFuture<Void> moveObject(String fromBucketName, String fromKey, String toBucketName,
String toKey) {
CopyObjectRequest copyObjectResult
= new CopyObjectRequest(fromBucketName, fromKey, toBucketName, toKey);
DeleteObjectRequest deleteObjectRequest = new DeleteObjectRequest(fromBucketName, fromKey);
return CompletableFuture.runAsync(
() -> {
s3Client.copyObject(copyObjectResult);
s3Client.deleteObject(deleteObjectRequest);
},
executorService
);
}
示例13: deleteBySha1
import com.amazonaws.services.s3.model.DeleteObjectRequest; //导入依赖的package包/类
@Override
public void deleteBySha1(final String tenant, final String sha1Hash) {
final String key = objectKey(tenant, sha1Hash);
LOG.info("Deleting S3 object from bucket {} and key {}", s3Properties.getBucketName(), key);
amazonS3.deleteObject(new DeleteObjectRequest(s3Properties.getBucketName(), key));
}
示例14: deleteObject
import com.amazonaws.services.s3.model.DeleteObjectRequest; //导入依赖的package包/类
public void deleteObject(AWSCredentials awsCredentials, String region, String bucket, String key) {
try {
runtimeCredentialsProvider.setAwsCredentials(awsCredentials);
amazonS3.setRegion(Region.getRegion(Regions.fromName(region)));
amazonS3.deleteObject(new DeleteObjectRequest(bucket, key));
} catch (AmazonClientException e) {
throw new OmakaseRuntimeException(e);
}
}
示例15: copy
import com.amazonaws.services.s3.model.DeleteObjectRequest; //导入依赖的package包/类
static void copy(
AmazonS3 s3Client,
String srcBucket,
String sourceKey,
String destBucket,
String destKey,
boolean isMove
) {
CopyObjectRequest cp = new CopyObjectRequest(srcBucket, sourceKey, destBucket, destKey);
s3Client.copyObject(cp);
if (isMove) {
s3Client.deleteObject(new DeleteObjectRequest(srcBucket, sourceKey));
}
}