/**
 * 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 at.illecker.storm.examples.util.io;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SerializationUtils {
  private static final Logger LOG = LoggerFactory
      .getLogger(SerializationUtils.class);

  public static <T extends Serializable> void serializeList(List<T> objects,
      String fileName) {
    // Assume List is Serializable
    // e.g., LinkedList or ArrayList
    if (objects instanceof java.io.Serializable) {
      SerializationUtils.serialize((Serializable) objects, fileName);
    } else {
      LOG.error("List is not serializable!");
    }
  }

  public static <T extends Serializable> void serialize(T object,
      String fileName) {
    try {
      FileOutputStream fos = new FileOutputStream(fileName);
      ObjectOutputStream oos = new ObjectOutputStream(fos);
      oos.writeObject(object);
      oos.close();
      fos.close();
      LOG.info("Serialized in " + fileName);
    } catch (FileNotFoundException fnfe) {
      LOG.error("FileNotFoundException: " + fnfe.getMessage());
    } catch (IOException ioe) {
      LOG.error("IOException: " + ioe.getMessage());
    }
  }

  public static <T extends Serializable> T deserialize(String fileName) {
    return deserialize(IOUtils.getInputStream(fileName));
  }

  public static <T extends Serializable> T deserialize(InputStream is) {
    T object = null;
    try {
      ObjectInputStream ois = new ObjectInputStream(is);
      object = (T) ois.readObject();
      ois.close();
      is.close();
    } catch (FileNotFoundException fnfe) {
      LOG.error("FileNotFoundException: " + fnfe.getMessage());
    } catch (IOException ioe) {
      LOG.error("IOException: " + ioe.getMessage());
    } catch (ClassNotFoundException c) {
      LOG.error("ClassNotFoundException: " + c.getMessage());
    }
    return object;
  }
}

@@ -1739,24 +1739,54 @@
 %7B%0A    try %7B%0A
+      if (object != null) %7B%0A  
       FileOu
@@ -1830,24 +1830,26 @@
 (fileName);%0A
+  
       Object
@@ -1898,24 +1898,26 @@
 fos);%0A      
+  
 oos.writeObj
@@ -1931,24 +1931,26 @@
 ect);%0A      
+ 
+ 
 oos.close();
@@ -1956,16 +1956,18 @@
 ;%0A      
+  
 fos.clos
@@ -1967,24 +1967,32 @@
 os.close();%0A
+      %7D%0A
       LOG.in
@@ -2464,24 +2464,50 @@
 ;%0A    try %7B%0A
+      if (is != null) %7B%0A  
       Object
@@ -2557,16 +2557,18 @@
 ;%0A      
+  
 object =
@@ -2586,24 +2586,26 @@
 adObject();%0A
+  
       ois.cl
@@ -2617,16 +2617,18 @@
 ;%0A      
+  
 is.close
@@ -2627,24 +2627,32 @@
 is.close();%0A
+      %7D%0A
     %7D catch 

Fix SerializationUtils