2323
2424import io .cloudevents .CloudEvent ;
2525import io .cloudevents .CloudEventData ;
26- import io .cloudevents .AvroCloudEvent ;
26+ import io .cloudevents .avro . AvroCloudEvent ;
2727import io .cloudevents .core .builder .CloudEventBuilder ;
2828import io .cloudevents .core .format .EventDeserializationException ;
2929import io .cloudevents .core .format .EventFormat ;
@@ -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 );
0 commit comments