Java 类org.apache.commons.io.input.ClassLoaderObjectInputStream 实例源码

项目:jstorm-0.9.6.3-    文件:Utils.java   
public static Object deserialize(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 ioe) {
        throw new RuntimeException(ioe);
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
}
项目:learn_jstorm    文件:Utils.java   
public static Object deserialize(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 ioe) {
        throw new RuntimeException(ioe);
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
}
项目:jstrom    文件:Utils.java   
/**
 * Deserialized with ClassLoader
 * 
 * @param serialized
 * @param loader
 * @return
 */
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 ioe) {
        throw new RuntimeException(ioe);
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
}
项目:Tstream    文件:Utils.java   
public static Object deserialize(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 ioe) {
        throw new RuntimeException(ioe);
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
}
项目:pygmy    文件:Utils.java   
/**
 * Loads a saved game from the device's memory
 * @return saved match if found, else returns null
 */
public static PygmyGame loadGameHistory(String path) {
    File file = new File(path);
    PygmyGame game = null;

    if (file.exists()) {
        try {
            ClassLoaderObjectInputStream ois = new ClassLoaderObjectInputStream(
                    PygmyLoader.getClassLoader(), new FileInputStream(file));
            game = (PygmyGame) ois.readObject();
            ois.close();
        } catch (Exception e) { 
            e.printStackTrace();
        }
    }
    return game;
}
项目:jstorm    文件:Utils.java   
/**
 * Deserialized with ClassLoader
 */
public static Object javaDeserializeWithCL(byte[] serialized, URLClassLoader loader) {
    try {
        ByteArrayInputStream bis = new ByteArrayInputStream(serialized);
        Object ret;
        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);
    }
}
项目:XPages-Scaffolding    文件:ModelDataContainer.java   
private void restoreWrappedObject() {
    try {
        if(modelObject_ == null) {
            // Then this must be a new request
            installFacesListener();

            ByteArrayInputStream bis = new ByteArrayInputStream(serializedModel_);
            FacesContext facesContext = FacesContext.getCurrentInstance();
            ClassLoaderObjectInputStream ois = new ClassLoaderObjectInputStream(facesContext.getContextClassLoader(), bis);
            modelObject_ = (ModelObject)ois.readObject();
            ois.close();
            bis.close();
            serializedModel_ = null;
        }
    } catch(Exception e) {
        e.printStackTrace();
    }
}
项目:Android_Code_Arbiter    文件:ObjectDeserialization.java   
public UserEntity deserializeObjectWithInheritance(InputStream receivedFile) throws IOException, ClassNotFoundException {
    ClassLoaderObjectInputStream in = new ClassLoaderObjectInputStream(getClass().getClassLoader(), receivedFile);
    try {
        return (UserEntity) in.readObject();
    }
    finally {
        in.close();
    }
}
项目:jstorm-0.9.6.3-    文件:SerializableSerializer.java   
@SuppressWarnings("resource")
@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);
    }
}
项目:learn_jstorm    文件:SerializableSerializer.java   
@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);
    }
}
项目:jstrom    文件:SerializableSerializer.java   
@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);
    }
}
项目:Tstream    文件:SerializableSerializer.java   
@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);
    }
}
项目:mxcache    文件:InstrumentationTestHelper.java   
@SuppressWarnings({ "unchecked" })
public static <T> T readWrite(T t) throws Exception {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(bos);
    try {
        oos.writeObject(t);
    } finally {
        oos.close();
    }
    return (T)new ClassLoaderObjectInputStream(t.getClass().getClassLoader(), new ByteArrayInputStream(bos.toByteArray())).readObject();
}
项目:nd4j    文件:VoidMessage.java   
static <T extends VoidMessage> T fromBytes(byte[] array) {
    try {
        ObjectInputStream in = new ClassLoaderObjectInputStream(Thread.currentThread().getContextClassLoader(),
                        new ByteArrayInputStream(array));

        T result = (T) in.readObject();
        return result;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    //return SerializationUtils.deserialize(array);
}
项目:normandra    文件:DataUtils.java   
public static <T extends Serializable> T bytesToObject(final Class<T> clazz, final byte[] value) {
    if (null == value || value.length <= 0) {
        return null;
    }
    try {
        final ByteArrayInputStream bytes = new ByteArrayInputStream(value);
        final ObjectInputStream input = new ClassLoaderObjectInputStream(clazz.getClassLoader(), bytes);
        final Object instance = input.readObject();
        IOUtils.closeQuietly(input);
        return clazz.cast(instance);
    } catch (final Exception e) {
        logger.warn("Unable to deserialize value [" + value + "] of type [" + clazz + "].", e);
        return null;
    }
}
项目:jstorm    文件:SerializableSerializer.java   
@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);
    }
}
项目:apex-core    文件:LogicalPlan.java   
public static LogicalPlan read(InputStream is) throws IOException, ClassNotFoundException
{
  return (LogicalPlan)new ClassLoaderObjectInputStream(Thread.currentThread().getContextClassLoader(), is).readObject();
}
项目:java-sandbox    文件:SerializationCloningStrategy.java   
private Object deserialize(byte[] serializedOriginal, ClassLoader targetLoader) throws ClassNotFoundException, IOException {
    ByteArrayInputStream byteStream = new ByteArrayInputStream(serializedOriginal);
    ClassLoaderObjectInputStream objectStream = new ClassLoaderObjectInputStream(targetLoader, byteStream);
    return objectStream.readObject();
}
项目:transloader    文件:SerializationCloningStrategy.java   
/**
 * {@inheritDoc}
 * 
 * @throws ClassCastException if the given <code>original</code> object is not {@link Serializable}
 * @throws SerializationException if serialization fails
 * @throws IOException if input fails during deserialization
 * @throws ClassNotFoundException if the <code>targetClassLoader</code> cannot find a required class
 */
public Object cloneObjectUsingClassLoader(Object original, ClassLoader targetClassLoader)
        throws ClassCastException, SerializationException, IOException, ClassNotFoundException {
    Assert.areNotNull(original, targetClassLoader);
    byte[] serializedOriginal = SerializationUtils.serialize((Serializable) original);
    return new ClassLoaderObjectInputStream(targetClassLoader, new ByteArrayInputStream(serializedOriginal)).readObject();
}