}
public void writeObject(Object toWrite) throws Exception {
try {
while ( !writeLock.compareAndSet(false,true) );
FSTObjectOutput objectOutput = conf.getObjectOutput(); // could also do new with minor perf impact
objectOutput.writeObject(toWrite);
int written = objectOutput.getWritten();
out.write((written >>> 0) & 0xFF);
out.write((written >>> 8) & 0xFF);
out.write((written >>> 16) & 0xFF);
out.write((written >>> 24) & 0xFF);
out.write(objectOutput.getBuffer(), 0, written);
objectOutput.flush();
} finally {
writeLock.set(false);
}
}