Skip to content

Commit ec8b996

Browse files
committed
Refactoring
1 parent 46362d6 commit ec8b996

File tree

19 files changed

+67
-39
lines changed

19 files changed

+67
-39
lines changed

awsec2instances/pom.xml

+1-6
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,14 @@
2020
<dependency>
2121
<groupId>software.amazon.awssdk</groupId>
2222
<artifactId>bom</artifactId>
23-
<version>2.14.5</version>
23+
<version>2.16.23</version>
2424
<type>pom</type>
2525
<scope>import</scope>
2626
</dependency>
2727
</dependencies>
2828
</dependencyManagement>
2929

3030
<dependencies>
31-
<dependency>
32-
<groupId>org.slf4j</groupId>
33-
<artifactId>slf4j-log4j12</artifactId>
34-
<version>1.7.30</version>
35-
</dependency>
3631
<dependency>
3732
<groupId>software.amazon.awssdk</groupId>
3833
<artifactId>ec2</artifactId>

awss3copy/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<dependency>
2121
<groupId>software.amazon.awssdk</groupId>
2222
<artifactId>bom</artifactId>
23-
<version>2.16.18</version>
23+
<version>2.16.23</version>
2424
<type>pom</type>
2525
<scope>import</scope>
2626
</dependency>

awss3copy/src/main/java/example/S3Copy.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
package example;
1111

12-
import java.io.IOException;
1312
import java.io.UnsupportedEncodingException;
1413
import java.net.URLEncoder;
1514
import java.nio.charset.StandardCharsets;
@@ -21,17 +20,20 @@
2120
import software.amazon.awssdk.services.s3.model.CopyObjectRequest;
2221
import software.amazon.awssdk.services.s3.model.CopyObjectResponse;
2322

23+
2424
public class S3Copy {
2525
private static final Region REGION = Region.of("eu-west-1"); // Region name
2626

27-
public static void main(String[] args) throws IOException {
27+
public static void main(String[] args) {
2828
String sourceBucketName; // Source bucket name
2929
String sourceKey; // Source key
3030
String destinationBucketName; // Destination bucket name
3131
String destinationKey; // Destination key
3232

3333
if (args.length < 3) {
34-
System.out.println("Not enough parameters.\nProper Usage is: java -jar s3copy.jar <SOURCE_BUCKET> <SOURCE_OBJECT> <DESTINATION_BUCKET>");
34+
System.out.println("Not enough parameters.\n" +
35+
"Proper Usage is: java -jar s3copy.jar " +
36+
"<SOURCE_BUCKET> <SOURCE_OBJECT> <DESTINATION_BUCKET>");
3537
System.exit(1);
3638
}
3739

awss3create/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<dependency>
2121
<groupId>software.amazon.awssdk</groupId>
2222
<artifactId>bom</artifactId>
23-
<version>2.16.14</version>
23+
<version>2.16.23</version>
2424
<type>pom</type>
2525
<scope>import</scope>
2626
</dependency>

awss3create/src/main/java/example/S3Create.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
package example;
99

10-
import java.io.IOException;
1110
import software.amazon.awssdk.core.exception.SdkException;
1211
import software.amazon.awssdk.awscore.exception.AwsServiceException;
1312
import software.amazon.awssdk.core.waiters.WaiterResponse;
@@ -25,10 +24,11 @@ public class S3Create {
2524

2625
private static final Region REGION = Region.of("eu-west-1"); // Region name
2726

28-
public static void main(String[] args) throws IOException {
27+
public static void main(String[] args) {
2928

3029
if (args.length < 1) {
31-
System.out.println("Not enough parameters.\nProper Usage is: java -jar s3create.jar <BUCKET_NAME>");
30+
System.out.println("Not enough parameters.\n" +
31+
"Proper Usage is: java -jar s3create.jar <BUCKET_NAME>");
3232
System.exit(1);
3333
}
3434

@@ -44,6 +44,7 @@ public static void main(String[] args) throws IOException {
4444

4545
try {
4646
System.out.println("Creating bucket ...");
47+
4748
S3Waiter s3Waiter = s3client.waiter();
4849
CreateBucketRequest bucketRequest = CreateBucketRequest.builder()
4950
.bucket(bucketName)
@@ -62,7 +63,9 @@ public static void main(String[] args) throws IOException {
6263
// Get Bucket location
6364
GetBucketLocationRequest bucketLocationRequest = GetBucketLocationRequest.builder().bucket(bucketName).build();
6465
GetBucketLocationResponse bucketLocationResponse = s3client.getBucketLocation(bucketLocationRequest);
66+
6567
System.out.println("Bucket location: " + bucketLocationResponse.locationConstraintAsString());
68+
6669
} catch (S3Exception e) {
6770
if (e.statusCode() == 409) {
6871
System.out.println("Error: Bucket already exists!!");

awss3delete/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<dependency>
2121
<groupId>software.amazon.awssdk</groupId>
2222
<artifactId>bom</artifactId>
23-
<version>2.16.14</version>
23+
<version>2.16.23</version>
2424
<type>pom</type>
2525
<scope>import</scope>
2626
</dependency>

awss3delete/src/main/java/example/S3Delete.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,22 @@
77

88
package example;
99

10-
import java.io.IOException;
1110
import software.amazon.awssdk.core.exception.SdkException;
1211
import software.amazon.awssdk.awscore.exception.AwsServiceException;
1312
import software.amazon.awssdk.regions.Region;
1413
import software.amazon.awssdk.services.s3.S3Client;
1514
import software.amazon.awssdk.services.s3.model.S3Exception;
1615
import software.amazon.awssdk.services.s3.model.DeleteBucketRequest;
1716

17+
1818
public class S3Delete {
1919
private static final Region REGION = Region.of("eu-west-1"); // Region name
2020

21-
public static void main(String[] args) throws IOException {
21+
public static void main(String[] args) {
2222

2323
if (args.length < 1) {
24-
System.out.println("Not enough parameters.\nProper Usage is: java -jar s3delete.jar <BUCKET_NAME>");
24+
System.out.println("Not enough parameters.\n" +
25+
"Proper Usage is: java -jar s3delete.jar <BUCKET_NAME>");
2526
System.exit(1);
2627
}
2728

@@ -37,10 +38,13 @@ public static void main(String[] args) throws IOException {
3738

3839
try {
3940
System.out.println("Deleting bucket ...");
41+
4042
// Delete bucket
4143
DeleteBucketRequest deleteBucketRequest = DeleteBucketRequest.builder().bucket(bucketName).build();
4244
s3client.deleteBucket(deleteBucketRequest);
45+
4346
System.out.println("Deleted");
47+
4448
} catch (S3Exception e) {
4549
if (e.statusCode() == 404) {
4650
System.out.println("Error: Bucket does not exist!!");

awss3deleteobject/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<dependency>
2121
<groupId>software.amazon.awssdk</groupId>
2222
<artifactId>bom</artifactId>
23-
<version>2.16.18</version>
23+
<version>2.16.23</version>
2424
<type>pom</type>
2525
<scope>import</scope>
2626
</dependency>

awss3deleteobject/src/main/java/example/S3DeleteObject.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
package example;
1010

11-
import java.io.IOException;
1211
import java.util.ArrayList;
1312
import software.amazon.awssdk.core.exception.SdkException;
1413
import software.amazon.awssdk.awscore.exception.AwsServiceException;
@@ -19,13 +18,16 @@
1918
import software.amazon.awssdk.services.s3.model.ObjectIdentifier;
2019
import software.amazon.awssdk.services.s3.model.DeleteObjectsRequest;
2120

21+
2222
public class S3DeleteObject {
2323
private static final Region REGION = Region.of("eu-west-1"); // Region name
2424

25-
public static void main(String[] args) throws IOException {
25+
public static void main(String[] args) {
2626

2727
if (args.length < 2) {
28-
System.out.println("Not enough parameters.\nProper Usage is: java -jar s3deleteobject.jar <BUCKET_NAME> <OBJECT_NAME>");
28+
System.out.println("Not enough parameters.\n" +
29+
"Proper Usage is: java -jar s3deleteobject.jar " +
30+
"<BUCKET_NAME> <OBJECT_NAME>");
2931
System.exit(1);
3032
}
3133

@@ -45,6 +47,7 @@ public static void main(String[] args) throws IOException {
4547

4648
try {
4749
System.out.println("Deleting object ...");
50+
4851
ArrayList<ObjectIdentifier> toDelete = new ArrayList<ObjectIdentifier>();
4952
toDelete.add(ObjectIdentifier.builder().key(keyName).build());
5053

@@ -54,7 +57,9 @@ public static void main(String[] args) throws IOException {
5457
.delete(Delete.builder().objects(toDelete).build())
5558
.build();
5659
s3client.deleteObjects(delReq);
60+
5761
System.out.println("Deleted");
62+
5863
} catch (S3Exception e) {
5964
if (e.statusCode() == 404) {
6065
System.out.println("Error: Bucket does not exist!!");

awss3download/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<dependency>
2121
<groupId>software.amazon.awssdk</groupId>
2222
<artifactId>bom</artifactId>
23-
<version>2.16.14</version>
23+
<version>2.16.23</version>
2424
<type>pom</type>
2525
<scope>import</scope>
2626
</dependency>

awss3download/src/main/java/example/S3Download.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,19 @@
2222
import software.amazon.awssdk.services.s3.model.GetObjectRequest;
2323
import software.amazon.awssdk.services.s3.model.GetObjectResponse;
2424

25+
2526
public class S3Download {
2627
private static final Region REGION = Region.of("eu-west-1"); // Region name
2728

28-
public static void main(String[] args) throws IOException {
29+
public static void main(String[] args) {
2930
String bucketName; // Source bucket name
3031
String keyName; // Key name, it is the object name
3132
String localFileName; // Local file name
3233

3334
if (args.length < 3) {
34-
System.out.println("Not enough parameters.\nProper Usage is: java -jar s3download.jar <BUCKET_NAME> <OBJECT_NAME> <LOCAL_FILE_NAME>");
35+
System.out.println("Not enough parameters.\n" +
36+
"Proper Usage is: java -jar s3download.jar " +
37+
"<BUCKET_NAME> <OBJECT_NAME> <LOCAL_FILE_NAME>");
3538
System.exit(1);
3639
}
3740

@@ -66,8 +69,11 @@ public static void main(String[] args) throws IOException {
6669
OutputStream os = new FileOutputStream(myFile);
6770
os.write(data);
6871
os.close();
72+
6973
System.out.println("Downloaded");
7074

75+
} catch (IOException ee) {
76+
System.err.println(ee.getMessage());
7177
} catch (S3Exception e) {
7278
if (e.statusCode() == 404) {
7379
System.out.println("Error: Bucket/Object \"" + bucketName + "/" + keyName + "\" does not exist!!");

awss3list/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<dependency>
2020
<groupId>software.amazon.awssdk</groupId>
2121
<artifactId>bom</artifactId>
22-
<version>2.16.14</version>
22+
<version>2.16.23</version>
2323
<type>pom</type>
2424
<scope>import</scope>
2525
</dependency>

awss3list/src/main/java/example/S3List.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
package example;
99

10-
import java.io.IOException;
1110
import java.util.List;
1211
import java.util.ListIterator;
1312
import software.amazon.awssdk.core.exception.SdkException;
@@ -19,15 +18,17 @@
1918
import software.amazon.awssdk.services.s3.model.ListObjectsResponse;
2019
import software.amazon.awssdk.services.s3.model.S3Object;
2120

21+
2222
public class S3List {
2323
private static final Region REGION = Region.of("eu-west-1"); // Region name
2424

25-
public static void main(String[] args) throws IOException {
25+
public static void main(String[] args) {
2626

2727
String bucketName; // Bucket name
2828

2929
if (args.length < 1) {
30-
System.out.println("Not enough parameters.\nProper Usage is: java -jar s3list.jar <BUCKET_NAME>");
30+
System.out.println("Not enough parameters.\n" +
31+
"Proper Usage is: java -jar s3list.jar <BUCKET_NAME>");
3132
System.exit(1);
3233
}
3334

@@ -43,6 +44,7 @@ public static void main(String[] args) throws IOException {
4344

4445
try {
4546
System.out.println("Listing objects ...");
47+
4648
ListObjectsRequest listObjects = ListObjectsRequest
4749
.builder()
4850
.bucket(bucketName)
@@ -57,6 +59,7 @@ public static void main(String[] args) throws IOException {
5759
" (size = " + myValue.size() + " bytes)" +
5860
" (owner = " + myValue.owner());
5961
}
62+
6063
System.out.println("Listed");
6164

6265
} catch (S3Exception e) {

awss3listall/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<dependency>
2020
<groupId>software.amazon.awssdk</groupId>
2121
<artifactId>bom</artifactId>
22-
<version>2.16.14</version>
22+
<version>2.16.23</version>
2323
<type>pom</type>
2424
<scope>import</scope>
2525
</dependency>

awss3listall/src/main/java/example/S3ListAll.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
package example;
77

8-
import java.io.IOException;
98
import java.util.List;
109
import java.util.ListIterator;
1110
import software.amazon.awssdk.core.exception.SdkException;
@@ -20,10 +19,11 @@
2019
import software.amazon.awssdk.services.s3.model.ListObjectsResponse;
2120
import software.amazon.awssdk.services.s3.model.S3Object;
2221

22+
2323
public class S3ListAll {
2424
private static final Region REGION = Region.of("eu-west-1"); // Region name
2525

26-
public static void main(String[] args) throws IOException {
26+
public static void main(String[] args) {
2727

2828
// Instantiates a client
2929
S3Client s3client = S3Client.builder()
@@ -32,6 +32,7 @@ public static void main(String[] args) throws IOException {
3232

3333
try {
3434
System.out.println("Listing S3 buckets and objects ...");
35+
3536
// List Buckets
3637
ListBucketsRequest listBucketsRequest = ListBucketsRequest.builder().build();
3738
ListBucketsResponse listBucketsResponse = s3client.listBuckets(listBucketsRequest);
@@ -55,7 +56,9 @@ public static void main(String[] args) throws IOException {
5556
" (owner = " + myValue.owner());
5657
}
5758
}
59+
5860
System.out.println("Listed");
61+
5962
} catch (S3Exception e) {
6063
System.out.println("S3Exception: " + e);
6164
System.out.println("HTTP Status Code: " + e.statusCode());

awss3move/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<dependency>
2121
<groupId>software.amazon.awssdk</groupId>
2222
<artifactId>bom</artifactId>
23-
<version>2.16.18</version>
23+
<version>2.16.23</version>
2424
<type>pom</type>
2525
<scope>import</scope>
2626
</dependency>

awss3move/src/main/java/example/S3Move.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
package example;
1111

12-
import java.io.IOException;
1312
import java.io.UnsupportedEncodingException;
1413
import java.util.ArrayList;
1514
import java.net.URLEncoder;
@@ -25,17 +24,20 @@
2524
import software.amazon.awssdk.services.s3.model.DeleteObjectsRequest;
2625
import software.amazon.awssdk.services.s3.model.Delete;
2726

27+
2828
public class S3Move {
2929
private static final Region REGION = Region.of("eu-west-1"); // Region name
3030

31-
public static void main(String[] args) throws IOException {
31+
public static void main(String[] args) {
3232
String sourceBucketName; // Source bucket name
3333
String sourceKey; // Source key
3434
String destinationBucketName; // Destination bucket name
3535
String destinationKey; // Destination key
3636

3737
if (args.length < 3) {
38-
System.out.println("Not enough parameters.\nProper Usage is: java -jar s3move.jar <SOURCE_BUCKET> <SOURCE_OBJECT> <DESTINATION_BUCKET>");
38+
System.out.println("Not enough parameters.\n" +
39+
"Proper Usage is: java -jar s3move.jar " +
40+
"<SOURCE_BUCKET> <SOURCE_OBJECT> <DESTINATION_BUCKET>");
3941
System.exit(1);
4042
}
4143

0 commit comments

Comments
 (0)