Search in sources :

Example 1 with ClassLoaderObjectInputStream

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);
    }
}
Also used : RT(clojure.lang.RT) ByteArrayInputStream(java.io.ByteArrayInputStream) ComponentObject(org.apache.storm.generated.ComponentObject) ClassLoaderObjectInputStream(org.apache.commons.io.input.ClassLoaderObjectInputStream) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream) ClassLoaderObjectInputStream(org.apache.commons.io.input.ClassLoaderObjectInputStream)

Example 2 with ClassLoaderObjectInputStream

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);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ComponentObject(backtype.storm.generated.ComponentObject) ClassLoaderObjectInputStream(org.apache.commons.io.input.ClassLoaderObjectInputStream) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream) ClassLoaderObjectInputStream(org.apache.commons.io.input.ClassLoaderObjectInputStream)

Example 3 with ClassLoaderObjectInputStream

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);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ClassLoaderObjectInputStream(org.apache.commons.io.input.ClassLoaderObjectInputStream) IOException(java.io.IOException)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)3 IOException (java.io.IOException)3 ClassLoaderObjectInputStream (org.apache.commons.io.input.ClassLoaderObjectInputStream)3 ObjectInputStream (java.io.ObjectInputStream)2 ComponentObject (backtype.storm.generated.ComponentObject)1 RT (clojure.lang.RT)1 ComponentObject (org.apache.storm.generated.ComponentObject)1