use of java.io.Externalizable in project ignite by apache.
the class OptimizedObjectOutputStream method writeExternalizable.
/**
* Writes externalizable object.
*
* @param obj Object.
* @throws IOException In case of error.
*/
void writeExternalizable(Object obj) throws IOException {
Externalizable extObj = (Externalizable) obj;
extObj.writeExternal(this);
}
use of java.io.Externalizable in project ignite by apache.
the class OptimizedObjectOutputStream method writeObject0.
/**
* Writes object to stream.
*
* @param obj Object.
* @throws IOException In case of error.
*/
private void writeObject0(Object obj) throws IOException {
curObj = null;
curFields = null;
curPut = null;
if (obj == null)
writeByte(NULL);
else {
if (obj instanceof Throwable && !(obj instanceof Externalizable)) {
writeByte(JDK);
try {
ctx.jdkMarshaller().marshal(obj, this);
} catch (IgniteCheckedException e) {
IOException ioEx = e.getCause(IOException.class);
if (ioEx != null)
throw ioEx;
else
throw new IOException("Failed to serialize object with JDK marshaller: " + obj, e);
}
} else {
OptimizedClassDescriptor desc = classDescriptor(clsMap, obj instanceof Object[] ? Object[].class : obj.getClass(), ctx, mapper);
if (desc.excluded()) {
writeByte(NULL);
return;
}
Object obj0 = desc.replace(obj);
if (obj0 == null) {
writeByte(NULL);
return;
}
int handle = -1;
if (!desc.isPrimitive() && !desc.isEnum() && !desc.isClass() && !desc.isProxy())
handle = handles.lookup(obj);
if (obj0 != obj) {
obj = obj0;
desc = classDescriptor(clsMap, obj instanceof Object[] ? Object[].class : obj.getClass(), ctx, mapper);
}
try {
if (handle >= 0) {
writeByte(HANDLE);
writeInt(handle);
} else
desc.write(this, obj);
} catch (IOException e) {
throw new IOException("Failed to serialize object [typeName=" + desc.describedClass().getName() + ']', e);
}
}
}
}
Aggregations