-
Notifications
You must be signed in to change notification settings - Fork 346
Expand file tree
/
Copy pathS3TransferExample.java
More file actions
43 lines (36 loc) · 1.6 KB
/
S3TransferExample.java
File metadata and controls
43 lines (36 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.amazonaws.samples;
import java.io.*;
import java.util.UUID;
public class S3TransferExample
{
private static File fileKey1;
private static File fileKey2;
private static String sourceBucket;
private static String destinationBucket;
public static void main(String[] args) {
createSourceAndDestinationBuckets("test-bucket-" + UUID.randomUUID());
fileKey1 = S3TestUtil.createTmpFile();
S3TestUtil.uploadTmpFileToBucket(sourceBucket, fileKey1);
fileKey2 = S3TestUtil.createTmpFile();
S3TestUtil.uploadTmpFileToBucket(sourceBucket, fileKey2);
copyBucketToNewLocation();
S3TestUtil.showAllBuckets();
//deleteTestBucketsNow();
}
private static void copyBucketToNewLocation() {
System.out.println("Copying bucket " + sourceBucket + " to new bucket " + destinationBucket);
//CopyObjectResult copyObjectResult = S3TestUtil.getS3().copyObject(sourceBucket, fileKey1.getName(), destinationBucket, fileKey1.getName());
S3TestUtil.copyEntireBucket(sourceBucket, destinationBucket);
}
public static void createSourceAndDestinationBuckets(String name)
{
sourceBucket = name;
destinationBucket = name + "-dest";
if (!S3TestUtil.bucketExists(sourceBucket)) S3TestUtil.createExpiringBucket(sourceBucket);
if (!S3TestUtil.bucketExists(destinationBucket)) S3TestUtil.createExpiringBucket(destinationBucket);
}
public static void deleteTestBucketsNow() {
S3TestUtil.deleteEntireBucket(sourceBucket);
S3TestUtil.deleteEntireBucket(destinationBucket);
}
}