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;
}
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);
}
}
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;
}
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);
}
}
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;
}
Aggregations