Search in sources :

Example 31 with ObjectStreamClass

use of java.io.ObjectStreamClass in project wildfly by wildfly.

the class Util method getIRIdentifierOfClass.

/**
     * Return the IR global ID of the given class or interface.
     * This is described in section 1.3.5.7.
     * The returned string is in the RMI hashed format, like
     * "RMI:java.util.Hashtable:C03324C0EA357270:13BB0F25214AE4B8".
     */
public static String getIRIdentifierOfClass(Class cls) {
    if (cls.isPrimitive())
        throw IIOPLogger.ROOT_LOGGER.primitivesHaveNoIRIds();
    String result = (String) classIRIdentifierCache.get(cls);
    if (result != null)
        return result;
    String name = cls.getName();
    StringBuffer b = new StringBuffer("RMI:");
    for (int i = 0; i < name.length(); ++i) {
        char c = name.charAt(i);
        if (c < 256)
            b.append(c);
        else
            b.append("\\U").append(toHexString((int) c));
    }
    long clsHash = getClassHashCode(cls);
    b.append(':').append(toHexString(clsHash));
    ObjectStreamClass osClass = ObjectStreamClass.lookup(cls);
    if (osClass != null) {
        long serialVersionUID = osClass.getSerialVersionUID();
        if (clsHash != serialVersionUID)
            b.append(':').append(toHexString(serialVersionUID));
    }
    result = b.toString();
    classIRIdentifierCache.put(cls, result);
    return result;
}
Also used : ObjectStreamClass(java.io.ObjectStreamClass)

Example 32 with ObjectStreamClass

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

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 33 with ObjectStreamClass

use of java.io.ObjectStreamClass in project camel by apache.

the class HBaseHelper method fromBytes.

public Object fromBytes(byte[] binary) {
    Object result = null;
    ObjectInputStream ois = null;
    if (binary == null) {
        return null;
    }
    ByteArrayInputStream bais = new ByteArrayInputStream(binary);
    final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    try {
        ois = new ObjectInputStream(bais) {

            @Override
            public Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
                try {
                    return classLoader.loadClass(desc.getName());
                } catch (Exception e) {
                }
                return super.resolveClass(desc);
            }
        };
        result = ois.readObject();
    } catch (IOException e) {
        LOG.warn("Error while deserializing object. Null will be used.", e);
    } catch (ClassNotFoundException e) {
        LOG.warn("Could not find class while deserializing object. Null will be used.", e);
    } finally {
        IOHelper.close(ois);
        IOHelper.close(bais);
    }
    return result;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectStreamClass(java.io.ObjectStreamClass) IOException(java.io.IOException) ObjectStreamClass(java.io.ObjectStreamClass) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

Example 34 with ObjectStreamClass

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

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 35 with ObjectStreamClass

use of java.io.ObjectStreamClass in project jdk8u_jdk by JetBrains.

the class MarshalInputStream method readClassDescriptor.

@Override
protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException {
    ObjectStreamClass descriptor = super.readClassDescriptor();
    validateDesc(descriptor);
    return descriptor;
}
Also used : ObjectStreamClass(java.io.ObjectStreamClass)

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