use of org.mule.runtime.core.privileged.store.DeserializationPostInitialisable in project mule by mulesoft.
the class SerializationUtils method deserialize.
/**
* <p>
* Deserializes an <code>Object</code> from the specified stream.
* </p>
* <p/>
* <p>
* The stream will be closed once the object is written. This avoids the need for a finally clause, and maybe also exception
* handling, in the application code.
* </p>
* <p/>
* <p>
* The stream passed in is not buffered internally within this method. This is the responsibility of your application if
* desired.
* </p>
*
* @param inputStream the serialized object input stream, must not be null
* @param cl classloader which can load custom classes from the stream
* @return the deserialized object
* @throws IllegalArgumentException if <code>inputStream</code> is <code>null</code>
* @throws org.apache.commons.lang3.SerializationException (runtime) if the serialization fails
*/
public static Object deserialize(InputStream inputStream, ClassLoader cl, MuleContext muleContext) {
if (inputStream == null) {
throw new IllegalArgumentException("The InputStream must not be null");
}
if (cl == null) {
throw new IllegalArgumentException("The ClassLoader must not be null");
}
ObjectInputStream in = null;
try {
// stream closed in the finally
in = new ClassLoaderObjectInputStream(cl, inputStream);
Object obj = in.readObject();
if (obj instanceof DeserializationPostInitialisable) {
DeserializationPostInitialisable.Implementation.init(obj, muleContext);
}
return obj;
} catch (ClassNotFoundException ex) {
throw new SerializationException(ex);
} catch (IOException ex) {
throw new SerializationException(ex);
} catch (Exception ex) {
throw new SerializationException(ex);
} finally {
try {
if (in != null) {
in.close();
}
} catch (IOException ex) {
// ignore close exception
}
}
}
Aggregations