Skip to content

Commit 19b49c9

Browse files
committed
updated S3 Java files to adhere to bucket names
1 parent 235ad53 commit 19b49c9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+464
-111
lines changed

javav2/example_code/s3/src/main/java/com/example/s3/AbortMultipartUploadExamples.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
*/
5555

5656
public class AbortMultipartUploadExamples {
57-
static final String bucketName = "amzn-s3-demo-bucket" + UUID.randomUUID();
57+
static final String bucketName = "amzn-s3-demo-bucket" + UUID.randomUUID(); // Change bucket name.
5858
static final String key = UUID.randomUUID().toString();
5959
static final String classPathFilePath = "/multipartUploadFiles/s3-userguide.pdf";
6060
static final String filePath = getFullFilePath(classPathFilePath);
@@ -78,6 +78,12 @@ public static void doAbortIncompleteMultipartUploadsFromList() {
7878
}
7979

8080
// snippet-start:[s3.java2.abort_upload_from_list]
81+
/**
82+
* Aborts all incomplete multipart uploads from the specified S3 bucket.
83+
* <p>
84+
* This method retrieves a list of all incomplete multipart uploads in the specified S3 bucket,
85+
* and then aborts each of those uploads.
86+
*/
8187
public static void abortIncompleteMultipartUploadsFromList() {
8288
ListMultipartUploadsRequest listMultipartUploadsRequest = ListMultipartUploadsRequest.builder()
8389
.bucket(bucketName)

javav2/example_code/s3/src/main/java/com/example/s3/BasicOpsWithChecksums.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
// snippet-start:[s3.java2.basicOpsWithChecksums.full]
4444
public class BasicOpsWithChecksums {
4545
static final S3Client s3Client = S3Client.create();
46-
static final String bucketName = "amzn-s3-demo-bucket" + UUID.randomUUID();
46+
static final String bucketName = "amzn-s3-demo-bucket" + UUID.randomUUID(); // Change bucket name.
4747
static final String key = UUID.randomUUID().toString();
4848
private static final Logger logger = LoggerFactory.getLogger(BasicOpsWithChecksums.class);
4949

javav2/example_code/s3/src/main/java/com/example/s3/CheckObjectIntegrity.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ public static void main(String[] args) {
8686
validateExistingFileAgainstS3Checksum(s3, bucketName, objectKey, objectPath);
8787
}
8888

89+
/**
90+
* Uploads an object to an Amazon S3 bucket using the Multipart Upload API, with the object being bracketed by a checksum.
91+
*
92+
* @param s3 The S3Client instance used to interact with the Amazon S3 service.
93+
* @param bucketName The name of the S3 bucket to upload the object to.
94+
* @param objectKey The key (name) of the object to be uploaded.
95+
* @param objectPath The local file path of the object to be uploaded.
96+
*/
8997
public static void putS3MultipartObjectBracketedByChecksum(S3Client s3, String bucketName, String objectKey,
9098
String objectPath) {
9199
System.out.println("Starting uploading file with additional checksum.");
@@ -137,6 +145,14 @@ public static void putS3MultipartObjectBracketedByChecksum(S3Client s3, String b
137145
}
138146
}
139147

148+
/**
149+
* Downloads an S3 object that is split into multiple parts, and verifies the checksum of each part as well as the
150+
* overall checksum of the entire object.
151+
*
152+
* @param s3 the S3 client used for interacting with the S3 service
153+
* @param bucketName the name of the S3 bucket where the object is located
154+
* @param objectKey the key of the S3 object to be downloaded
155+
*/
140156
public static void downloadS3MultipartObjectBracketedByChecksum(S3Client s3, String bucketName,
141157
String objectKey) {
142158
System.out.println("Starting downloading file and doing validation");
@@ -196,6 +212,16 @@ public static void downloadS3MultipartObjectBracketedByChecksum(S3Client s3, Str
196212
}
197213
}
198214

215+
/**
216+
* Validates the locally persisted file against the checksum stored in Amazon S3.
217+
*
218+
* @param s3 The S3Client instance to interact with Amazon S3.
219+
* @param bucketName The name of the S3 bucket where the object is stored.
220+
* @param objectKey The key of the S3 object to be validated.
221+
* @param objectPath The local file path of the object to be validated.
222+
* @throws IOException If there is an error reading the local file or validating the checksum.
223+
* @throws NoSuchAlgorithmException If the specified algorithm (SHA-256) is not available.
224+
*/
199225
public static void validateExistingFileAgainstS3Checksum(S3Client s3, String bucketName, String objectKey,
200226
String objectPath) {
201227
System.out.println("Starting validating the locally persisted file.");

javav2/example_code/s3/src/main/java/com/example/s3/CopyObjectStorage.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ public static void main(String[] args) {
5151
s3.close();
5252
}
5353

54+
/**
55+
* Copies an object from one Amazon S3 bucket to another, and stores the object in the DEEP_ARCHIVE storage class.
56+
*
57+
* @param s3 the S3Client object used to interact with the Amazon S3 service
58+
* @param fromBucket the name of the bucket from which the object is being copied
59+
* @param objectKey the name of the object to be copied
60+
* @param toBucket the name of the bucket to which the object is being copied
61+
*/
5462
public static void copyBucketObject(S3Client s3, String fromBucket, String objectKey, String toBucket) {
5563
CopyObjectRequest copyReq = CopyObjectRequest.builder()
5664
.sourceBucket(fromBucket)

javav2/example_code/s3/src/main/java/com/example/s3/CreateAccessPoint.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,16 @@ public static void main(String[] args) {
5353
s3ControlClient.close();
5454
}
5555

56-
// This method creates an access point for the given Amazon S3 bucket.
56+
/**
57+
* Creates a specific access point on an Amazon S3 bucket.
58+
*
59+
* @param s3ControlClient the S3 Control client to use for the operation
60+
* @param accountId the AWS account ID associated with the bucket
61+
* @param bucketName the name of the S3 bucket
62+
* @param accessPointName the name of the access point to be created
63+
*
64+
* @throws S3ControlException if there is an error creating the access point
65+
*/
5766
public static void createSpecificAccessPoint(S3ControlClient s3ControlClient, String accountId, String bucketName,
5867
String accessPointName) {
5968
try {
@@ -72,6 +81,14 @@ public static void createSpecificAccessPoint(S3ControlClient s3ControlClient, St
7281
}
7382
}
7483

84+
/**
85+
* Deletes a specific S3 access point.
86+
*
87+
* @param s3ControlClient the S3 Control client to use for the operation
88+
* @param accountId the account ID of the access point to delete
89+
* @param accessPointName the name of the access point to delete
90+
* @throws S3ControlException if an error occurs while deleting the access point
91+
*/
7592
public static void deleteSpecificAccessPoint(S3ControlClient s3ControlClient, String accountId,
7693
String accessPointName) {
7794
try {

javav2/example_code/s3/src/main/java/com/example/s3/DeleteBucketPolicy.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ public static void main(String[] args) {
4747
s3.close();
4848
}
4949

50+
/**
51+
* Deletes the S3 bucket policy for the specified bucket.
52+
*
53+
* @param s3 the {@link S3Client} instance to use for the operation
54+
* @param bucketName the name of the S3 bucket for which the policy should be deleted
55+
*
56+
* @throws S3Exception if there is an error deleting the bucket policy
57+
*/
5058
public static void deleteS3BucketPolicy(S3Client s3, String bucketName) {
5159
DeleteBucketPolicyRequest delReq = DeleteBucketPolicyRequest.builder()
5260
.bucket(bucketName)

javav2/example_code/s3/src/main/java/com/example/s3/DeleteMultiObjects.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ public static void main(String[] args) {
5252
s3.close();
5353
}
5454

55+
/**
56+
* Deletes multiple objects from an Amazon S3 bucket.
57+
*
58+
* @param s3 An Amazon S3 client object.
59+
* @param bucketName The name of the Amazon S3 bucket to delete objects from.
60+
*/
5561
public static void deleteBucketObjects(S3Client s3, String bucketName) {
5662
// Upload three sample objects to the specfied Amazon S3 bucket.
5763
ArrayList<ObjectIdentifier> keys = new ArrayList<>();

javav2/example_code/s3/src/main/java/com/example/s3/DeleteWebsiteConfiguration.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ public static void main(String[] args) {
4848
s3.close();
4949
}
5050

51+
/**
52+
* Deletes the website configuration for an Amazon S3 bucket.
53+
*
54+
* @param s3 The {@link S3Client} instance used to interact with Amazon S3.
55+
* @param bucketName The name of the S3 bucket for which the website configuration should be deleted.
56+
* @throws S3Exception If an error occurs while deleting the website configuration.
57+
*/
5158
public static void deleteBucketWebsiteConfig(S3Client s3, String bucketName) {
5259
DeleteBucketWebsiteRequest delReq = DeleteBucketWebsiteRequest.builder()
5360
.bucket(bucketName)

javav2/example_code/s3/src/main/java/com/example/s3/GeneratePresignedGetUrlAndRetrieve.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class GeneratePresignedGetUrlAndRetrieve {
4848
private final static S3Client s3Client = S3Client.create();
4949

5050
public static void main(String[] args) {
51-
String bucketName = "amzn-s3-demo-bucket" + UUID.randomUUID();
51+
String bucketName = "amzn-s3-demo-bucket" + UUID.randomUUID(); // Change bucket name.
5252
String keyName = "key" + UUID.randomUUID();
5353
String resourcePath = "multipartUploadFiles/s3-userguide.pdf";
5454

javav2/example_code/s3/src/main/java/com/example/s3/GeneratePresignedUrlAndPutFileWithMetadata.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class GeneratePresignedUrlAndPutFileWithMetadata {
5252
private final static S3Client s3Client = S3Client.create();
5353

5454
public static void main(String[] args) {
55-
String bucketName = "amzn-s3-demo-bucket" + UUID.randomUUID();
55+
String bucketName = "amzn-s3-demo-bucket" + UUID.randomUUID(); // Change bucket name.
5656
String keyName = "key" + UUID.randomUUID();
5757
String resourcePath = "multipartUploadFiles/s3-userguide.pdf";
5858
// Uncomment the following two lines and comment out the previous two lines to use an image file instead of a PDF file.

0 commit comments

Comments
 (0)