Coverage Report - org.mule.util.SerializationUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
SerializationUtils
0%
0/34
0%
0/14
4.333
 
 1  
 /*
 2  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.util;
 8  
 
 9  
 import org.mule.api.MuleContext;
 10  
 import org.mule.util.store.DeserializationPostInitialisable;
 11  
 
 12  
 import java.io.ByteArrayInputStream;
 13  
 import java.io.IOException;
 14  
 import java.io.InputStream;
 15  
 import java.io.ObjectInputStream;
 16  
 
 17  
 import org.apache.commons.io.input.ClassLoaderObjectInputStream;
 18  
 import org.apache.commons.lang.SerializationException;
 19  
 
 20  0
 public class SerializationUtils extends org.apache.commons.lang.SerializationUtils
 21  
 {
 22  
     public static Object deserialize(InputStream inputStream, MuleContext muleContext)
 23  
     {
 24  0
         if (muleContext == null)
 25  
         {
 26  0
             throw new IllegalArgumentException("The MuleContext must not be null");
 27  
         }
 28  0
         return deserialize(inputStream, muleContext.getExecutionClassLoader(), muleContext);
 29  
     }
 30  
 
 31  
     public static Object deserialize(byte[] objectData, MuleContext muleContext)
 32  
     {
 33  0
         if (muleContext == null)
 34  
         {
 35  0
             throw new IllegalArgumentException("The MuleContext must not be null");
 36  
         }
 37  0
         return deserialize(objectData, muleContext.getExecutionClassLoader(), muleContext);        
 38  
     }
 39  
     
 40  
     /**
 41  
      * <p>Deserializes an <code>Object</code> from the specified stream.</p>
 42  
      * <p/>
 43  
      * <p>The stream will be closed once the object is written. This
 44  
      * avoids the need for a finally clause, and maybe also exception
 45  
      * handling, in the application code.</p>
 46  
      * <p/>
 47  
      * <p>The stream passed in is not buffered internally within this method.
 48  
      * This is the responsibility of your application if desired.</p>
 49  
      *
 50  
      * @param inputStream the serialized object input stream, must not be null
 51  
      * @param cl          classloader which can load custom classes from the stream
 52  
      * @return the deserialized object
 53  
      * @throws IllegalArgumentException if <code>inputStream</code> is <code>null</code>
 54  
      * @throws org.apache.commons.lang.SerializationException
 55  
      *                                  (runtime) if the serialization fails
 56  
      */
 57  
     private static Object deserialize(InputStream inputStream, ClassLoader cl, MuleContext muleContext)
 58  
     {
 59  0
         if (inputStream == null)
 60  
         {
 61  0
             throw new IllegalArgumentException("The InputStream must not be null");
 62  
         }
 63  0
         if (cl == null)
 64  
         {
 65  0
             throw new IllegalArgumentException("The ClassLoader must not be null");
 66  
         }
 67  0
         ObjectInputStream in = null;
 68  
         try
 69  
         {
 70  
             // stream closed in the finally
 71  0
             in = new ClassLoaderObjectInputStream(cl, inputStream);
 72  0
             Object obj = in.readObject();
 73  0
             if (obj instanceof DeserializationPostInitialisable)
 74  
             {
 75  0
                 DeserializationPostInitialisable.Implementation.init(obj, muleContext);
 76  
             }
 77  0
             return obj;
 78  
         }
 79  0
         catch (ClassNotFoundException ex)
 80  
         {
 81  0
             throw new SerializationException(ex);
 82  
         }
 83  0
         catch (IOException ex)
 84  
         {
 85  0
             throw new SerializationException(ex);
 86  
         }
 87  0
         catch (Exception ex)
 88  
         {
 89  0
             throw new SerializationException(ex);
 90  
         }
 91  
         finally
 92  
         {
 93  0
             try
 94  
             {
 95  0
                 if (in != null)
 96  
                 {
 97  0
                     in.close();
 98  
                 }
 99  
             }
 100  0
             catch (IOException ex)
 101  
             {
 102  
                 // ignore close exception
 103  0
             }
 104  
         }
 105  
     }
 106  
 
 107  
     /**
 108  
      * <p>Deserializes a single <code>Object</code> from an array of bytes.</p>
 109  
      *
 110  
      * @param objectData the serialized object, must not be null
 111  
      * @param cl         classloader which can load custom classes from the stream
 112  
      * @return the deserialized object
 113  
      * @throws IllegalArgumentException if <code>objectData</code> is <code>null</code>
 114  
      * @throws SerializationException   (runtime) if the serialization fails
 115  
      */
 116  
     private static Object deserialize(byte[] objectData, ClassLoader cl, MuleContext muleContext)
 117  
     {
 118  0
         if (objectData == null)
 119  
         {
 120  0
             throw new IllegalArgumentException("The byte[] must not be null");
 121  
         }
 122  0
         ByteArrayInputStream bais = new ByteArrayInputStream(objectData);
 123  0
         return deserialize(bais, cl, muleContext);
 124  
     }
 125  
     
 126  
     /**
 127  
      * @deprecated Call deserialize(InputStream inputStream, MuleContext muleContext) instead
 128  
      */
 129  
     public static Object deserialize(InputStream inputStream, ClassLoader cl)
 130  
     {
 131  0
         return deserialize(inputStream, cl, null);
 132  
     }
 133  
     
 134  
     /**
 135  
      * @deprecated Call deserialize(byte[] objectData, MuleContext muleContext) instead
 136  
      */
 137  
     public static Object deserialize(byte[] objectData, ClassLoader cl)
 138  
     {
 139  0
         return deserialize(objectData, cl, null);
 140  
     }    
 141  
 }