Skip to content

Commit 123bf68

Browse files
committed
addressing some review comments for avro format
1 parent 8505d78 commit 123bf68

File tree

5 files changed

+14
-20
lines changed

5 files changed

+14
-20
lines changed

formats/avro/pom.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
<properties>
3535
<avro.version>1.9.2</avro.version>
36+
<build.helper.version>3.2.0</build.helper.version>
3637
<module-name>io.cloudevents.formats.avro</module-name>
3738
</properties>
3839

@@ -41,7 +42,7 @@
4142
<plugin>
4243
<groupId>org.apache.avro</groupId>
4344
<artifactId>avro-maven-plugin</artifactId>
44-
<version>1.10.2</version>
45+
<version>${avro.version}</version>
4546
<executions>
4647
<execution>
4748
<phase>generate-sources</phase>
@@ -59,7 +60,7 @@
5960
<plugin>
6061
<groupId>org.codehaus.mojo</groupId>
6162
<artifactId>build-helper-maven-plugin</artifactId>
62-
<version>3.2.0</version>
63+
<version>${build.helper.version}</version>
6364
<executions>
6465
<execution>
6566
<id>add-source</id>

formats/avro/src/main/avro/spec.avsc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"namespace":"io.cloudevents",
2+
"namespace":"io.cloudevents.avro",
33
"type":"record",
44
"name":"AvroCloudEvent",
55
"version":"1.0",
@@ -61,4 +61,3 @@
6161
}
6262
]
6363
}
64-

formats/avro/src/main/java/io/cloudevents/avro/AvroCloudEventDataWrapper.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@
1818

1919
import java.io.ByteArrayOutputStream;
2020
import java.io.IOException;
21-
import java.util.List;
2221
import java.util.Map;
2322

2423
import io.cloudevents.AvroCloudEventData;
2524
import io.cloudevents.CloudEventData;
25+
import io.cloudevents.core.format.EventDeserializationException;
2626

2727
/**
2828
* Encode JSON style cloudevent data into Avro format.
2929
*
3030
*/
3131
public class AvroCloudEventDataWrapper implements CloudEventData {
3232

33-
private AvroCloudEventData avroCloudEventData;
33+
private final AvroCloudEventData avroCloudEventData;
3434

3535
/**
3636
* Wraps a JSON object-like data structure.
@@ -42,13 +42,11 @@ public AvroCloudEventDataWrapper(Map<String, Object> data) {
4242

4343
@Override
4444
public byte[] toBytes() {
45-
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
46-
try {
45+
try (ByteArrayOutputStream bytes = new ByteArrayOutputStream()) {
4746
AvroCloudEventData.getEncoder().encode(this.avroCloudEventData, bytes);
48-
} catch (IOException ignore) {
49-
// ignored
47+
return bytes.toByteArray();
48+
} catch (IOException e) {
49+
throw new EventDeserializationException(e);
5050
}
51-
52-
return bytes.toByteArray();
5351
}
5452
}

formats/avro/src/main/java/io/cloudevents/avro/AvroFormat.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,19 @@ public class AvroFormat implements EventFormat {
3737
@Override
3838
public byte[] serialize(CloudEvent event) throws EventSerializationException {
3939
AvroCloudEvent avroCloudEvent = AvroSerializer.toAvro(event);
40-
ByteArrayOutputStream output = new ByteArrayOutputStream();
4140

42-
try {
41+
try (ByteArrayOutputStream output = new ByteArrayOutputStream()) {
4342
AvroCloudEvent.getEncoder().encode(avroCloudEvent, output);
43+
return output.toByteArray();
4444
} catch (IOException e) {
4545
throw new EventSerializationException(e);
4646
}
47-
48-
return output.toByteArray();
4947
}
5048

5149
@Override
5250
public CloudEvent deserialize(byte[] bytes, CloudEventDataMapper<? extends CloudEventData> mapper)
5351
throws EventDeserializationException {
54-
ByteArrayInputStream input = new ByteArrayInputStream(bytes);
55-
56-
try {
52+
try (ByteArrayInputStream input = new ByteArrayInputStream(bytes)) {
5753
AvroCloudEvent avroCloudEvent = AvroCloudEvent.getDecoder().decode(input);
5854

5955
return new AvroDeserializer(avroCloudEvent).read(CloudEventBuilder::fromSpecVersion, mapper);

formats/avro/src/main/java/io/cloudevents/avro/AvroSerializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
class AvroSerializer {
3030

31-
public static final AvroCloudEvent toAvro(CloudEvent e) {
31+
static final AvroCloudEvent toAvro(CloudEvent e) {
3232
AvroCloudEvent avroCloudEvent = new AvroCloudEvent();
3333

3434
Map<String, Object> attrs = new HashMap<>();

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy