/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.apache.heron.api.serializer;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Map;

public class JavaSerializer implements IPluggableSerializer {

  @Override
  public void initialize(Map<String, Object> config) {
  }

  @Override
  public byte[] serialize(Object object) {
    try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
         ObjectOutputStream oos = new ObjectOutputStream(bos)) {
      oos.writeObject(object);
      oos.flush();
      return bos.toByteArray();
    } catch (IOException ex) {
      throw new RuntimeException("Failed to serialize object: " + object.toString(), ex);
    }
  }

  @Override
  public Object deserialize(byte[] input) {
    try (ByteArrayInputStream bis = new ByteArrayInputStream(input);
          ObjectInputStream ois = new ObjectInputStream(bis)) {
      return ois.readObject();
    } catch (IOException | ClassNotFoundException ex) {
      throw new RuntimeException(ex);
    }
  }
}

@@ -1226,37 +1226,32 @@
 t object) %7B%0A    
-try (
 ByteArrayOutputS
@@ -1290,24 +1290,31 @@
 tream();%0A   
+ try %7B%0A
       Object
@@ -1359,19 +1359,17 @@
 eam(bos)
-) %7B
+;
 %0A      o
@@ -1415,40 +1415,8 @@
 ();%0A
-      return bos.toByteArray();%0A
     
@@ -1429,33 +1429,32 @@
 h (IOException e
-x
 ) %7B%0A      throw 
@@ -1527,17 +1527,16 @@
 ing(), e
-x
 );%0A    %7D
@@ -1532,24 +1532,54 @@
 , e);%0A    %7D%0A
+    return bos.toByteArray();%0A
   %7D%0A%0A  @Over
@@ -1635,13 +1635,8 @@
     
-try (
 Byte
@@ -1691,24 +1691,30 @@
 input);%0A    
+try %7B%0A
       Object
@@ -1757,19 +1757,17 @@
 eam(bis)
-) %7B
+;
 %0A      r
@@ -1841,17 +1841,16 @@
 eption e
-x
 ) %7B%0A    
@@ -1879,17 +1879,16 @@
 eption(e
-x
 );%0A    %7D

Revert "refactor JavaSerializer for closing input/output stream"