本文整理汇总了Java中com.amazonaws.services.s3.AmazonS3.listVersions方法的典型用法代码示例。如果您正苦于以下问题:Java AmazonS3.listVersions方法的具体用法?Java AmazonS3.listVersions怎么用?Java AmazonS3.listVersions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.s3.AmazonS3
的用法示例。
在下文中一共展示了AmazonS3.listVersions方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: emptyBucket
import com.amazonaws.services.s3.AmazonS3; //导入方法依赖的package包/类
/**
* Empties the contents of the given bucket and optionally deletes the bucket
*
* @param s3 The S3 client object to use
* @param bucketName The bucket to empty
* @param deleteBucket Flag to determine whether to delete the bucket after emptying
* @param context Lambda context object
*/
public static void emptyBucket(AmazonS3 s3, String bucketName, boolean deleteBucket, Context context)
{
if (s3.doesBucketExistV2(bucketName))
{
logDebug("Emptying bucket '" + bucketName + "'...", context);
VersionListing versionListing = s3.listVersions(new ListVersionsRequest().withBucketName(bucketName));
while (true)
{
for (S3VersionSummary vs : versionListing.getVersionSummaries())
{
s3.deleteVersion(bucketName, vs.getKey(), vs.getVersionId());
}
if (versionListing.isTruncated())
{
logDebug("Fetching next batch of versions for bucket '" + bucketName + "'", context);
versionListing = s3.listNextBatchOfVersions(versionListing);
}
else
{
break;
}
}
logInfo("Successfully emptied bucket '" + bucketName + "'", context);
if (deleteBucket)
{
logDebug("Deleting bucket '" + bucketName + "'...", context);
s3.deleteBucket(bucketName);
logInfo("Successfully deleted bucket '" + bucketName + "'", context);
}
}
else
{
logWarn("Bucket '" + bucketName + "' does not exist", context);
}
}