Skip to content

Commit 71b9df7

Browse files
committed
Make Generator classes non-instantiable (they are static utility classes).
1 parent 5ec8b5f commit 71b9df7

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

examples/powertools-examples-kafka/tools/src/main/java/org/demo/kafka/tools/GenerateAvroSamples.java

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,60 +16,66 @@
1616
*/
1717
public class GenerateAvroSamples {
1818

19+
private GenerateAvroSamples() {
20+
// Utility class
21+
}
22+
1923
public static void main(String[] args) throws IOException {
2024
// Create three different products
2125
AvroProduct product1 = new AvroProduct(1001, "Laptop", 999.99);
2226
AvroProduct product2 = new AvroProduct(1002, "Smartphone", 599.99);
2327
AvroProduct product3 = new AvroProduct(1003, "Headphones", 149.99);
24-
28+
2529
// Serialize and encode each product
2630
String encodedProduct1 = serializeAndEncode(product1);
2731
String encodedProduct2 = serializeAndEncode(product2);
2832
String encodedProduct3 = serializeAndEncode(product3);
29-
33+
3034
// Serialize and encode an integer key
3135
String encodedKey = serializeAndEncodeInteger(42);
32-
36+
3337
// Print the results
3438
System.out.println("Base64 encoded Avro products for use in kafka-avro-event.json:");
3539
System.out.println("\nProduct 1 (with key):");
3640
System.out.println("key: \"" + encodedKey + "\",");
3741
System.out.println("value: \"" + encodedProduct1 + "\",");
38-
42+
3943
System.out.println("\nProduct 2 (with key):");
4044
System.out.println("key: \"" + encodedKey + "\",");
4145
System.out.println("value: \"" + encodedProduct2 + "\",");
42-
46+
4347
System.out.println("\nProduct 3 (without key):");
4448
System.out.println("key: null,");
4549
System.out.println("value: \"" + encodedProduct3 + "\",");
46-
50+
4751
// Print a sample event structure
4852
System.out.println("\nSample event structure:");
4953
printSampleEvent(encodedKey, encodedProduct1, encodedProduct2, encodedProduct3);
5054
}
51-
55+
5256
private static String serializeAndEncode(AvroProduct product) throws IOException {
5357
ByteArrayOutputStream baos = new ByteArrayOutputStream();
5458
BinaryEncoder encoder = EncoderFactory.get().binaryEncoder(baos, null);
5559
DatumWriter<AvroProduct> writer = new SpecificDatumWriter<>(AvroProduct.class);
56-
60+
5761
writer.write(product, encoder);
5862
encoder.flush();
59-
63+
6064
return Base64.getEncoder().encodeToString(baos.toByteArray());
6165
}
62-
66+
6367
private static String serializeAndEncodeInteger(Integer value) throws IOException {
6468
// For simple types like integers, we'll just convert to string and encode
6569
return Base64.getEncoder().encodeToString(value.toString().getBytes());
6670
}
67-
71+
6872
private static void printSampleEvent(String key, String product1, String product2, String product3) {
6973
System.out.println("{\n" +
7074
" \"eventSource\": \"aws:kafka\",\n" +
71-
" \"eventSourceArn\": \"arn:aws:kafka:us-east-1:0123456789019:cluster/SalesCluster/abcd1234-abcd-cafe-abab-9876543210ab-4\",\n" +
72-
" \"bootstrapServers\": \"b-2.demo-cluster-1.a1bcde.c1.kafka.us-east-1.amazonaws.com:9092,b-1.demo-cluster-1.a1bcde.c1.kafka.us-east-1.amazonaws.com:9092\",\n" +
75+
" \"eventSourceArn\": \"arn:aws:kafka:us-east-1:0123456789019:cluster/SalesCluster/abcd1234-abcd-cafe-abab-9876543210ab-4\",\n"
76+
+
77+
" \"bootstrapServers\": \"b-2.demo-cluster-1.a1bcde.c1.kafka.us-east-1.amazonaws.com:9092,b-1.demo-cluster-1.a1bcde.c1.kafka.us-east-1.amazonaws.com:9092\",\n"
78+
+
7379
" \"records\": {\n" +
7480
" \"mytopic-0\": [\n" +
7581
" {\n" +

examples/powertools-examples-kafka/tools/src/main/java/org/demo/kafka/tools/GenerateJsonSamples.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
*/
1414
public class GenerateJsonSamples {
1515

16+
private GenerateJsonSamples() {
17+
// Utility class
18+
}
19+
1620
public static void main(String[] args) throws IOException {
1721
// Create three different products
1822
Map<String, Object> product1 = new HashMap<>();

examples/powertools-examples-kafka/tools/src/main/java/org/demo/kafka/tools/GenerateProtobufSamples.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
*/
1515
public class GenerateProtobufSamples {
1616

17+
private GenerateProtobufSamples() {
18+
// Utility class
19+
}
20+
1721
public static void main(String[] args) throws IOException {
1822
// Create a single product that will be used for all three scenarios
1923
ProtobufProduct product = ProtobufProduct.newBuilder()

0 commit comments

Comments
 (0)