You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@heron.apache.org by GitBox <gi...@apache.org> on 2018/09/20 19:02:46 UTC

[GitHub] nlu90 closed pull request #3031: refactor JavaSerializer for proper closing input/output streams

nlu90 closed pull request #3031: refactor JavaSerializer for proper closing input/output streams
URL: https://github.com/apache/incubator-heron/pull/3031
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/heron/api/src/java/org/apache/heron/api/serializer/JavaSerializer.java b/heron/api/src/java/org/apache/heron/api/serializer/JavaSerializer.java
index 75a1fba041..9a024c9ecf 100644
--- a/heron/api/src/java/org/apache/heron/api/serializer/JavaSerializer.java
+++ b/heron/api/src/java/org/apache/heron/api/serializer/JavaSerializer.java
@@ -34,25 +34,23 @@ public void initialize(Map<String, Object> config) {
 
   @Override
   public byte[] serialize(Object object) {
-    ByteArrayOutputStream bos = new ByteArrayOutputStream();
-    try {
-      ObjectOutputStream oos = new ObjectOutputStream(bos);
+    try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
+         ObjectOutputStream oos = new ObjectOutputStream(bos)) {
       oos.writeObject(object);
       oos.flush();
+      return bos.toByteArray();
     } catch (IOException e) {
       throw new RuntimeException("Failed to serialize object: " + object.toString(), e);
     }
-    return bos.toByteArray();
   }
 
   @Override
   public Object deserialize(byte[] input) {
-    ByteArrayInputStream bis = new ByteArrayInputStream(input);
-    try {
-      ObjectInputStream ois = new ObjectInputStream(bis);
+    try (ByteArrayInputStream bis = new ByteArrayInputStream(input);
+         ObjectInputStream ois = new ObjectInputStream(bis)) {
       return ois.readObject();
     } catch (IOException | ClassNotFoundException e) {
-      throw new RuntimeException(e);
+      throw new RuntimeException("Failed to deserialize object", e);
     }
   }
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services