use of org.apache.commons.io.input.ClassLoaderObjectInputStream in project storm by apache.
the class Utils method javaDeserialize.
public static <T> T javaDeserialize(byte[] serialized, Class<T> clazz) {
try {
ByteArrayInputStream bis = new ByteArrayInputStream(serialized);
ObjectInputStream ois = null;
if (null == cl) {
ois = new ObjectInputStream(bis);
} else {
// Use custom class loader set in testing environment
ois = new ClassLoaderObjectInputStream(cl, bis);
}
Object ret = ois.readObject();
ois.close();
return (T) ret;
} catch (IOException ioe) {
throw new RuntimeException(ioe);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
use of org.apache.commons.io.input.ClassLoaderObjectInputStream in project jstorm by alibaba.
the class Utils method javaDeserializeWithCL.
/**
* Deserialized with ClassLoader
*/
public static Object javaDeserializeWithCL(byte[] serialized, URLClassLoader loader) {
try {
ByteArrayInputStream bis = new ByteArrayInputStream(serialized);
Object ret = null;
if (loader != null) {
ClassLoaderObjectInputStream cis = new ClassLoaderObjectInputStream(loader, bis);
ret = cis.readObject();
cis.close();
} else {
ObjectInputStream ois = new ObjectInputStream(bis);
ret = ois.readObject();
ois.close();
}
return ret;
} catch (IOException | ClassNotFoundException ioe) {
throw new RuntimeException(ioe);
}
}
use of org.apache.commons.io.input.ClassLoaderObjectInputStream in project jstorm by alibaba.
the class SerializableSerializer method read.
@Override
public Object read(Kryo kryo, Input input, Class c) {
int len = input.readInt();
byte[] ser = new byte[len];
input.readBytes(ser);
ByteArrayInputStream bis = new ByteArrayInputStream(ser);
try {
ClassLoaderObjectInputStream ois = new ClassLoaderObjectInputStream(kryo.getClassLoader(), bis);
return ois.readObject();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations