Search in sources :

Example 41 with ObjectStreamClass

use of java.io.ObjectStreamClass in project android_frameworks_base by crdroidandroid.

the class Parcel method readSerializable.

private final Serializable readSerializable(final ClassLoader loader) {
    String name = readString();
    if (name == null) {
        // return null, which indicates that the name wasn't found in the parcel.
        return null;
    }
    byte[] serializedData = createByteArray();
    ByteArrayInputStream bais = new ByteArrayInputStream(serializedData);
    try {
        ObjectInputStream ois = new ObjectInputStream(bais) {

            @Override
            protected Class<?> resolveClass(ObjectStreamClass osClass) throws IOException, ClassNotFoundException {
                // try the custom classloader if provided
                if (loader != null) {
                    Class<?> c = Class.forName(osClass.getName(), false, loader);
                    if (c != null) {
                        return c;
                    }
                }
                return super.resolveClass(osClass);
            }
        };
        return (Serializable) ois.readObject();
    } catch (IOException ioe) {
        throw new RuntimeException("Parcelable encountered " + "IOException reading a Serializable object (name = " + name + ")", ioe);
    } catch (ClassNotFoundException cnfe) {
        throw new RuntimeException("Parcelable encountered " + "ClassNotFoundException reading a Serializable object (name = " + name + ")", cnfe);
    }
}
Also used : Serializable(java.io.Serializable) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) ObjectStreamClass(java.io.ObjectStreamClass) ObjectInputStream(java.io.ObjectInputStream)

Example 42 with ObjectStreamClass

use of java.io.ObjectStreamClass in project Payara by payara.

the class SerializableWorkContext method getSerializable.

public Serializable getSerializable() throws IOException, ClassNotFoundException {
    if (object != null) {
        return object;
    }
    ByteArrayInputStream bin = new ByteArrayInputStream(data);
    ObjectInputStream in = new ObjectInputStream(bin) {

        @Override
        protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
            try {
                return Class.forName(desc.getName(), false, Thread.currentThread().getContextClassLoader());
            } catch (ClassNotFoundException cnfe) {
                return super.resolveClass(desc);
            }
        }

        @SuppressWarnings("rawtypes")
        @Override
        protected Class<?> resolveProxyClass(String[] interfaces) throws IOException, ClassNotFoundException {
            ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
            ClassLoader nonPublicLoader = null;
            boolean hasNonPublicInterface = false;
            Class[] classObjs = new Class[interfaces.length];
            for (int i = 0; i < interfaces.length; i++) {
                Class cl = Class.forName(interfaces[i], false, ctxLoader);
                if ((cl.getModifiers() & Modifier.PUBLIC) == 0) {
                    if (hasNonPublicInterface) {
                        if (nonPublicLoader != cl.getClassLoader()) {
                            throw new IllegalAccessError("conflicting non-public interface class loaders");
                        }
                    } else {
                        nonPublicLoader = cl.getClassLoader();
                        hasNonPublicInterface = true;
                    }
                }
                classObjs[i] = cl;
            }
            try {
                return Proxy.getProxyClass(hasNonPublicInterface ? nonPublicLoader : ctxLoader, classObjs);
            } catch (IllegalArgumentException e) {
                throw new ClassNotFoundException(null, e);
            }
        }
    };
    Serializable obj = (Serializable) in.readObject();
    in.close();
    if (obj instanceof Carrier) {
        object = ((Carrier) obj).getSerializable();
        this.mutable = ((Carrier) obj).isMutable();
    } else {
        object = obj;
    }
    return object;
}
Also used : Serializable(java.io.Serializable) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectStreamClass(java.io.ObjectStreamClass) ObjectStreamClass(java.io.ObjectStreamClass) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

ObjectStreamClass (java.io.ObjectStreamClass)42 ByteArrayInputStream (java.io.ByteArrayInputStream)15 ObjectInputStream (java.io.ObjectInputStream)15 IOException (java.io.IOException)12 ObjectOutputStream (java.io.ObjectOutputStream)8 ObjectStreamField (java.io.ObjectStreamField)6 Serializable (java.io.Serializable)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 DataInputStream (java.io.DataInputStream)1 EOFException (java.io.EOFException)1 InputStream (java.io.InputStream)1 PipedInputStream (java.io.PipedInputStream)1 PipedOutputStream (java.io.PipedOutputStream)1 StreamCorruptedException (java.io.StreamCorruptedException)1 BufferUnderflowException (java.nio.BufferUnderflowException)1 SerializationException (krati.io.SerializationException)1 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)1 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)1 FileContext (org.apache.hadoop.fs.FileContext)1 Path (org.apache.hadoop.fs.Path)1