Search in sources :

Example 1 with ConfigurableObjectInputStream

use of org.springframework.core.ConfigurableObjectInputStream in project spring-security-oauth by spring-projects.

the class SerializationUtils method deserialize.

public static <T> T deserialize(byte[] byteArray) {
    ObjectInputStream oip = null;
    try {
        oip = new ConfigurableObjectInputStream(new ByteArrayInputStream(byteArray), Thread.currentThread().getContextClassLoader());
        @SuppressWarnings("unchecked") T result = (T) oip.readObject();
        return result;
    } catch (IOException e) {
        throw new IllegalArgumentException(e);
    } catch (ClassNotFoundException e) {
        throw new IllegalArgumentException(e);
    } finally {
        if (oip != null) {
            try {
                oip.close();
            } catch (IOException e) {
            // eat it
            }
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) ConfigurableObjectInputStream(org.springframework.core.ConfigurableObjectInputStream) ConfigurableObjectInputStream(org.springframework.core.ConfigurableObjectInputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 2 with ConfigurableObjectInputStream

use of org.springframework.core.ConfigurableObjectInputStream in project spring-integration by spring-projects.

the class WhiteListDeserializingConverter method deserialize.

protected Object deserialize(ByteArrayInputStream inputStream) throws IOException {
    try {
        ObjectInputStream objectInputStream = new ConfigurableObjectInputStream(inputStream, this.defaultDeserializerClassLoader) {

            @Override
            protected Class<?> resolveClass(ObjectStreamClass classDesc) throws IOException, ClassNotFoundException {
                Class<?> clazz = super.resolveClass(classDesc);
                checkWhiteList(clazz);
                return clazz;
            }
        };
        return objectInputStream.readObject();
    } catch (ClassNotFoundException ex) {
        throw new NestedIOException("Failed to deserialize object type", ex);
    }
}
Also used : NestedIOException(org.springframework.core.NestedIOException) ObjectStreamClass(java.io.ObjectStreamClass) ConfigurableObjectInputStream(org.springframework.core.ConfigurableObjectInputStream) ConfigurableObjectInputStream(org.springframework.core.ConfigurableObjectInputStream) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

ObjectInputStream (java.io.ObjectInputStream)2 ConfigurableObjectInputStream (org.springframework.core.ConfigurableObjectInputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 ObjectStreamClass (java.io.ObjectStreamClass)1 NestedIOException (org.springframework.core.NestedIOException)1