} else {
String userToken = args[4];
String productToken = args[5];
credentials = new AWSDevPayCredentials(accessKey, secretKey, userToken, productToken);
}
S3Service service = new RestS3Service(credentials);
// Find all current multipart uploads
List<MultipartUpload> multipartUploads =
service.multipartListUploads(bucketName);
// Identify only multipart uploads older than a certain date
// (to try and avoid killing off an in-progress upload)
long CUTOFF = System.currentTimeMillis() - (hoursAgo * 60 * 60 * 1000);
List<MultipartUpload> oldMultipartUploads = new ArrayList<MultipartUpload>();
for (MultipartUpload multipartUpload: multipartUploads) {
if (multipartUpload.getInitiatedDate().getTime() < CUTOFF) {
oldMultipartUploads.add(multipartUpload);
}
}
System.out.println("Of " + multipartUploads.size() + " multipart upload(s) in "
+ bucketName + ", " + oldMultipartUploads.size() + " are older than "
+ hoursAgo + " hours ago");
// If no candidates for deletion, no work to do
if (oldMultipartUploads.size() < 1) {
return;
}
// Prompt user to confirm deletion
System.out.print("About to delete " + oldMultipartUploads.size()
+ " multipart uploads, is this OK? (y/n) ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String response = br.readLine();
if (!"y".equals(response.toLowerCase()) && !"yes".equals(response.toLowerCase())) {
System.out.println("Aborting");
return;
}
// Delete old multipart uploads
for (MultipartUpload multipartUpload: oldMultipartUploads) {
System.out.print("Deleting (aborting) " + multipartUpload + " ...");
service.multipartAbortUpload(multipartUpload);
System.out.println(" done.");
}
}