if (toWrite == null) {
toWrite = objectAndPersistInfo;
}
}
if (!objectAndPersistInfo.isLoadedOrNotAProxy()) {
throw new ObjectIOException("can not store not loaded object");
}
final DataRecordIdentifier dataRecordIdentifier = toWrite.dataRecordIdentifier;
// /**/getKnownDataRecordIdentifierAssociatedToObject(toWrite);
if (logger.debugEnabled) {
logger.debug("begin store: data record " + dataRecordIdentifier);
}
/* the object class can be different than object.getClass() */
final IObjectOutput objectOutput;
objectOutput = getObjectOutput(classInfo);
assert !toWrite.isSubstituted();
objectOutput.prepareWrite(toWrite);
final int byteSizeForObject = objectOutput.byteSize(toWrite,
HEADER_DATA_SIZE);
/*
* "long byte size" added to length for object and store data record
* identifier
*/
final byte[] binary = new byte[HelperBinaryConversion.INT_BYTE_SIZE
+ HelperBinaryConversion.LONG_BYTE_SIZE + byteSizeForObject];
int offset = 0;
try {
/* first data is data record identifier */
offset = helperBinaryConversion.longConverter.toBinary(binary,
offset, true, dataRecordIdentifier.value);
/* second is data for object length */
offset = helperBinaryConversion.integerConverter.toBinary(binary,
offset, true, byteSizeForObject);
/* third data is class name identifier */
final int classNameIdentifier = classNameManager
.getIdentifier(classInfo);
/* the data header */
offset = helperBinaryConversion.integerConverter.toBinary(binary,
offset, true, Integer.valueOf(classNameIdentifier));
} catch (final BinaryConverterException exception) {
throw new ObjectIOException(exception);
}
if (offset != HEADER_DATA_SIZE) {
throw new ObjectIOException("header data size miss match");
}
/* then object serialization */
objectOutput.writeBody(binary, offset, toWrite, false);
try {
changeFileOutputStream.write(binary, 0, binary.length);
} catch (final IOException exception) {
throw new ObjectIOException(exception);
}
if (logger.debugEnabled) {
logger.debug("end store: data record " + dataRecordIdentifier);
}