use of java.io.ObjectStreamClass in project knime-core by knime.
the class Config method readDataCell.
/**
* Reads and creates a new Object from the given serialized object stream.
*
* @param string The serialized object's stream.
* @return A new instance of this object.
* @throws IOException if an I/O error occurs during reading the object
* @throws ClassNotFoundException if the class of the serialized object
* cannot be found.
*/
private static final Object readDataCell(final String className, final String serString) throws IOException, ClassNotFoundException {
byte[] bytes = Base64.getDecoder().decode(serString);
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
ObjectInputStream ois;
if (className == null) {
ois = new ObjectInputStream(bais);
} else {
final Class<? extends DataCell> dataCellClass = DataTypeRegistry.getInstance().getCellClass(className).orElseThrow(() -> new ClassNotFoundException("No data cell implementation '" + className + "' found"));
ois = new ObjectInputStream(bais) {
@Override
protected Class<?> resolveClass(final ObjectStreamClass desc) throws IOException, ClassNotFoundException {
if (desc.getName().equals(className)) {
return dataCellClass;
}
// if the class to be loaded is not a DataCell
try {
return Class.forName(desc.getName(), true, dataCellClass.getClassLoader());
} catch (ClassNotFoundException cnfe) {
// ignore and let super try to do it.
}
return super.resolveClass(desc);
}
};
}
Object o = ois.readObject();
ois.close();
return o;
}
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;
}
use of java.io.ObjectStreamClass in project gradle by gradle.
the class PayloadSerializerObjectInputStream method readClassDescriptor.
@Override
protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException {
Class<?> aClass = readClass();
ObjectStreamClass descriptor = ObjectStreamClass.lookupAny(aClass);
if (descriptor == null) {
throw new ClassNotFoundException(aClass.getName());
}
return descriptor;
}
use of java.io.ObjectStreamClass in project wildfly by wildfly.
the class ContainerAnalysis method calculateRepositoryId.
/**
* 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".
*/
protected void calculateRepositoryId() {
if (cls.isArray() || cls.isPrimitive())
throw IIOPLogger.ROOT_LOGGER.notAnClassOrInterface(cls.getName());
if (cls.isInterface() && org.omg.CORBA.Object.class.isAssignableFrom(cls) && org.omg.CORBA.portable.IDLEntity.class.isAssignableFrom(cls)) {
StringBuffer b = new StringBuffer("IDL:");
b.append(cls.getPackage().getName().replace('.', '/'));
b.append('/');
String base = cls.getName();
base = base.substring(base.lastIndexOf('.') + 1);
b.append(base).append(":1.0");
repositoryId = b.toString();
} else {
StringBuffer b = new StringBuffer("RMI:");
b.append(escapeIRName(cls.getName()));
memberPrefix = b.toString() + ".";
String hashStr = toHexString(classHashCode);
b.append(':').append(hashStr);
ObjectStreamClass osClass = ObjectStreamClass.lookup(cls);
if (osClass != null) {
long serialVersionUID = osClass.getSerialVersionUID();
String SVUID = toHexString(serialVersionUID);
if (classHashCode != serialVersionUID)
b.append(':').append(SVUID);
memberPostfix = ":" + hashStr + ":" + SVUID;
} else
memberPostfix = ":" + hashStr;
repositoryId = b.toString();
}
}
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;
}
Aggregations