PutKeyValueCommand cmd = new PutKeyValueCommand(
"k", "v", false, null, new EmbeddedMetadata.Builder().build(), Collections.<Flag>emptySet(), AnyEquivalence.getInstance());
try {
// Write
StreamingMarshaller globalMarshal = extractGlobalMarshaller(cm);
ExposedByteArrayOutputStream baos = new ExposedByteArrayOutputStream(1024);
ObjectOutput globalOO = globalMarshal.startObjectOutput(baos, false, 1024);
try {
globalOO.writeObject(address);
/** BEGIN: Special treatment **/
globalOO.flush(); // IMPORTANT: Flush needed to make sure the address gets written!!
globalOO.writeInt(baos.size()); // Note amount of bytes that have been read so far
globalOO.flush(); // IMPORTANT: Flush again!
/** END: Special treatment **/
// Now try cache marshaller to 'borrow' the output stream
StreamingMarshaller cacheMarshaller = extractCacheMarshaller(cm.getCache());
ObjectOutput cacheOO = cacheMarshaller.startObjectOutput(baos, true, 1024);
try {
cacheOO.writeObject(cmd);
} finally {
cacheMarshaller.finishObjectOutput(cacheOO);
}
} finally {
globalMarshal.finishObjectOutput(globalOO);
}
byte[] bytes = new byte[baos.size()];
System.arraycopy(baos.getRawBuffer(), 0, bytes, 0, bytes.length);
// Read
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
ObjectInput globalOI = globalMarshal.startObjectInput(bais, false);
try {